2011-03-08 15 views
1

我是Android新手,請幫我設計下面的佈局。非常感謝。用省略號然後是計數器的佈局

我想實現一個佈局,它顯示一個文本後跟一個計數器。如果文本太長,請顯示...,然後是計數器。如下圖所示:

預計的佈局:

短信(3)//當屏幕寬度足夠

長文本等等BL ...(2)//當屏幕寬度不夠

下面是我的xml。當文本短時,它通常顯示在1以上。當文本很長時,問題是: 1)文本末尾不顯示「...」 2)計數器(2)未顯示在屏幕上。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_weight="1" 
    > 

    <TextView android:id="@+id/text" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:text="very long body safbadaf asfasf safasfd" 
     android:layout_gravity="left" 
     android:paddingLeft="4dp" android:paddingTop="8dp" 
     android:paddingRight="4dp" android:paddingBottom="8dp" 
     android:textStyle="bold" android:singleLine="true" android:ellipsize="end"/> 
    <TextView android:id="@+id/count" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:text="count" 
     android:layout_gravity="center_horizontal" 
     android:paddingLeft="4dp" android:paddingTop="8dp" 
     android:paddingRight="4dp" android:paddingBottom="8dp" 
     android:textStyle="bold" android:singleLine="true" android:layout_weight="1" /> 
</LinearLayout> 

威廉

回答

1

設置android:layout_weight="1"用於第一TextView的,而不是第二個。也爲第一個textview設置layout_width =「0」而不是wrap_content

+0

Frieza,謝謝!但「0」不是layout_width的有效值。 – william

+0

對不起我嘗試「0dp」 – pankajagarwal