我试图让文本行,这将是这样的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