代码之家  ›  专栏  ›  技术社区  ›  aioobe

Android AppWidget布局问题与ellipsize

  •  1
  • aioobe  · 技术社区  · 14 年前

    布局如下所示:

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

    问题是 如果标签和数字的宽度对于小部件来说太宽,请将其省略。我想要那个 标签 被省略。

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

    .-----------------------------.
    | 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>
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   CommonsWare    14 年前

    我怀疑你的问题,部分原因是 android:layout_width="wrap_content"

    我会离开 LinearLayout RelativeLayout . 将数字“列”定义为 android:layout_alignParentRight="true" . 将标签“列”定义为 android:layout_alignParentLeft="true" , android:layout_toLeftOf="..." ... 是您的数字列),并且 android:ellpsize="end"