I have used this code in the past to solve the problem:

In this case the text field is called "descr", my layout settings are
"android:gravity="center_vertical|center_horizontal" and I put this
code in a special cursor handler:

TextView tv = (TextView) v.findViewById(R.id.descr);
tv.setText(DescrText);
if ( DescrText.length() > 30 )
        tv.setSingleLine(false);
else
        tv.setSingleLine(true);

The android gravity respects the "setSingleLine" attribute and makes
the output very pretty.

tc


On Apr 23, 1:43 pm, Manish Garg <[email protected]> wrote:
> :-(. I dont think it will be good workaround. I need to make my
> application compatible to different form factor and in case of tablet
> it is coming in one line. So I can't put new line character.
>
> On Apr 22, 3:10 pm, Kostya Vasilyev <[email protected]> wrote:
>
> > Manish,
>
> > As far as I can tell, when TextView breaks text into multiple lines, it
> > always takes as much width from the parent view as it can.
>
> > One possible workaround is to include explicit linesbreaks, "\n", into
> > the string.
>
> > -- Kostya
>
> > 22.04.2011 22:53, Manish Garg пишет:
>
> > > Hi All,
>
> > > In my application, I am displaying some text in textview on tabs. I
> > > have customized tabs view. because of the text length it is wrapping
> > > in two line which is fine with me.
>
> > > But this text is getting aligned with the left and no more in center
> > > of the tab view.
>
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <LinearLayout
> > >    xmlns:android="http://schemas.android.com/apk/res/android";
> > >    android:layout_width="fill_parent"
> > >    android:layout_height="fill_parent"
> > >    android:background="@layout/mailbox_tab_bg_state"
> > >    android:gravity="center">
>
> > >    <TextView
> > >            android:id="@+id/tabTxt"
> > >            android:text="list view"
> > >            android:layout_width="wrap_content"
> > >            android:layout_height="wrap_content"
> > >            android:textColor="@layout/tab_text_color_selector">
> > >    </TextView>
> > > </LinearLayout>
>
> > > I tried to set text view's gravity property as center then text in two
> > > line get in center but it wasn't left aligned with respect to each
> > > other. I wish that lines should be in center of the tab view and left
> > > aligned with themselves.
>
> > > Thanks&  Regards,
> > > Manish Garg
>
> > --
> > Kostya Vasilyev --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to