Android layout 如何强制选中复选框';要不换行的文本是什么?

Android layout 如何强制选中复选框';要不换行的文本是什么?,android-layout,android-linearlayout,android-button,android-checkbox,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 and

这是我的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>
…同时将复选框的布局权重从1更改为2(按钮设置为1),这也满足了我的需求:


复选框继承自CompoundButton,它继承自Button,它继承自文本视图。因此,它具有这些祖先的所有属性、方法和属性 参考:

特别是,您对文本视图属性、方法和属性感兴趣:
参考:

特别是,您对android:lines属性感兴趣,并将其设置为1
这会告诉您的复选框的高度为恰好1行

您可能还希望将
android:ellipsize
属性设置为某个值(即:3=end)。
这会告诉您的复选框在结束、开始、中心等处添加三个点(省略号)。。。被截断的文本

[编辑]


作为TextView的一员,它可以使用
设置单行线
——感谢@CrandellWS的评论。

谢谢;我还必须将复选框的权重从1更改为2(按钮的权重设置为1)。我在更新中显示了令人满意的结果。复选框是TextView与java的分心人,可以使用
setSingleLine
see->@CrandellWS谢谢您的评论。我在回答中补充了这一点。在继续研究的同时,我发现了另一个可能是可取的选择
setHorizontallyScrolling(布尔值)
see->relavance最好在->
android:lines="1"