1

我正在编写一个显示一些数字的应用程序小部件,每个数字前面都有标签。

布局如下所示:

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

有一个外部(垂直)LinearLayout,每一行是一个带有两个 TextView 的水平 LinearLayout。

问题是如果标签的宽度和数字对于小部件来说太宽,数字会变成椭圆形。我希望标签变成椭圆形。

例如,上述情况最终会是这样的:

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

而不是想要的

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

我无法为我的生活弄清楚如何解决这个问题。任何帮助表示赞赏。


我目前的布局如下:

<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>
4

1 回答 1

2

我怀疑你的问题,部分是你android:layout_width="wrap_content"的标签。我根本不希望它变成椭圆形,因为有足够的空间来展示它。

我会从 切换LinearLayoutRelativeLayout。将您的数字“列”定义为android:layout_alignParentRight="true"android:layout_width="wrap_content"。将您的标签“列”定义为android:layout_alignParentLeft="true"android:layout_toLeftOf="..."...您的数字列在哪里)和android:ellpsize="end"。这应该为数字提供它需要的所有空间并限制标签,迫使它变成椭圆形。

于 2010-08-02T20:58:47.857 回答