B. *_*non 3 android-layout android-linearlayout android-button android-checkbox
这就是我的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>
Run Code Online (Sandbox Code Playgroud)
...需要更改以强制我的复选框文本不要换行?
遵循Der Golem的建议添加:
android:lines="1"
Run Code Online (Sandbox Code Playgroud)
...并且还将复选框的layout_weight从1更改为2(按钮设置为1)给了我想要的内容:

CheckBox继承自CompoundButton,后者继承自Button,后者继承自TextView.因此,它具有这些祖先的所有属性,方法和属性...
参考:http://developer.android.com/reference/android/widget/CheckBox.html
特别是,您对TextView属性,方法和属性感兴趣:
参考:http://developer.android.com/reference/android/widget/TextView.html
特别是,您对该android:lines属性感兴趣,并将其设置为1.
这告诉您的CheckBox 正好是 1行高.
您可能还希望将android:ellipsize属性设置为某个值(即:3 =结束).
这告诉你的CheckBox在截断文本的结尾,开始,中心等处添加三个点(省略号).
[编辑]
作为TextView的一个优势,它可以使用setSingleLine- 感谢@CrandellWS的评论.
| 归档时间: |
|
| 查看次数: |
2041 次 |
| 最近记录: |