views:

127

answers:

1

I'm writing an app-widget that displays some numbers, each with label in front of it.

The layout looks like this:

.-----------------------------.
| Label1       |  AAAAAAAAAAA |
| LongerLabelLabel2 | BBBBBBB |
| LongLabel3    | CCCCCCCCCC  |
'-----------------------------'

There is one outer (vertical) LinearLayout, and each row is a horizontal LinearLayout with two TextViews.

The problem is that the numbers get ellipsized if the width of the label and the number is too wide for the widget. I want the labels to get ellipsized.

The above situation for instance, would end up like this:

.-----------------------------.
| Label1    |     AAAAAAAAAAA |
| LongerLabelLabel2 | BBBB... |
| LongLabel3 |    CCCCCCCCCC  |
'-----------------------------'

instead of the desired

.---------------------------.
| Label1     |  AAAAAAAAAAA |
| LongerLabelL... | BBBBBBB |
| LongLabel3  | CCCCCCCCCC  |
'---------------------------'

I can't for my life figure out how to solve this. Any help is appreciated.


My current layout is the following:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="0dip"
    android:orientation="vertical"
    style="@style/WidgetBackground">


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:id="@+id/ROW1"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:paddingTop="7dip"
              android:paddingBottom="0dip"
              android:paddingRight="10dip"
              android:paddingLeft="10dip"
              android:orientation="horizontal">
        <TextView android:id="@+id/NAME1" android:singleLine="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" style="@style/Text.account" />
        <TextView android:id="@+id/BAL1"  android:singleLine="true" android:layout_width="fill_parent"  android:layout_height="wrap_content" android:gravity="right" style="@style/Text.balance" />
    </LinearLayout>

... (more similar rows in the outer layout)

</LinearLayout>
+1  A: 

I suspect your problem, in part, is that you have android:layout_width="wrap_content" for your label. I would not expect it to ellipsize at all, since there is enough room to show it.

I would switch away from LinearLayout to RelativeLayout. Define your number "column" as android:layout_alignParentRight="true" and android:layout_width="wrap_content". Define your label "column" as android:layout_alignParentLeft="true", android:layout_toLeftOf="..." (where ... is your number column), and android:ellpsize="end". That should give the number all the space it needs and constrain the label, forcing it to ellipsize.

CommonsWare
Ah.. I looked at RelativeLayout but couldn't figure out how to do it... I'll give it a shot with your instructions. Thanks!
aioobe
Works like a charm! Thanks a lot!!
aioobe