我試圖讓文本行,這將是這樣的Android的佈局使用layout_weight,layout_width和maxWidth
foofoofoo - barbarbar
,但我希望它橢圓foo和bar,如果它贏得了」 t適合一條線。 即我試圖縮短它們。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="0dip"
android:layout_weight="1"
android:textColor="#ffffff"
android:singleLine="true"
android:ellipsize="true"
android:text="foofoofoofoo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text=" - " />
<TextView
android:id="@+id/text_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="0dip"
android:layout_weight="1"
android:textColor="#ffffff"
android:singleLine="true"
android:ellipsize="true"
android:text="barbarbarbar" />
</LinearLayout>
熊與我這部分工作。
設置TextView
的layout_width
爲0dip
和layout_weight
是1
意味着它們會佔用每個可用空間的50%。
設置singleLine
到true
和ellipsize
到true
意味着他們會像foofoo ...如果文本比容器大。
因此,我的結果(如果文字是更長的時間)應該是
foofoo .. - BARBAR ..
它是!所以這個工作。
現在我試圖解決的情況下,如果第一TextView
(ID:文本1)具有文本小於由layout_width="0dip"
和layout_weight="1"
我希望它wrap_content
給出的50%。否則,它看起來像:
富空白- BARBAR ..
,我想
富 - barbarbar
這就是爲什麼我更改了layout_width="wrap_content"
並添加了android:maxWidth="0dip"
但這不起作用!它似乎無視我說wrap_content
,仍然給這個觀點50%!
我讀到,你需要添加android:adjustViewBounds="true"
爲maxWidth
工作,但這沒有任何影響。
我想基本上說maxWidth是共享空間(因此elipsing),但通常只是wrap_content。所以我會假設它會wrap_content,除非wrap_content的dip值> 50%,那麼它會使用maxWidth(這是50%),不是? – Blundell 2011-02-10 20:25:29
`除非wrap_content的dip值> 50%,那麼它會使用maxWidth` ...我真的不知道你想說什麼。 `wrap_content`不使用dip值。 – user432209 2011-02-10 23:38:38