这就是我的 LinearLayout(水平)行的样子:
我希望复选框的文本在一行上;按钮不必那么宽 - 它们仍然有足够的空间,并且复选框文本稍微加长。我的 XML 中的内容:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/ckbxAllow_New_Items"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:checked="true"
android:text="@string/checkbox_Allow_New_Items" />
<Button
android:id="@+id/btnOK"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_OK" />
<Button
android:id="@+id/btnCancel"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_Cancel" />
</LinearLayout>
...需要更改以强制我的复选框文本不换行?
UPDATE
按照 Der Golem 的建议添加以下内容:
android:lines="1"
...并且还将复选框的layout_weight从1更改为2(按钮设置为1)给了我我想要的:
CheckBox继承自CompoundButton,CompoundButton继承自Button,Button继承自TextView。所以,它具有这些的所有属性、方法和属性祖先...
参考:http://developer.android.com/reference/android/widget/CheckBox.html http://developer.android.com/reference/android/widget/CheckBox.html
您尤其感兴趣的是TextView属性、方法和属性:
参考:http://developer.android.com/reference/android/widget/TextView.html http://developer.android.com/reference/android/widget/TextView.html
您尤其感兴趣的是android:lines
属性,并将其设置为1.
这告诉你的复选框是exactly1 行高。
您可能还想设置android:ellipsize
属性为某个值(即:3 = end)。
这告诉您的复选框在截断文本的末尾、开始、中心等处添加三个点(省略号)。
[EDIT]
作为 TextView 的后代,id 可以使用setSingleLine
- 感谢@CrandellWS 的评论。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)