gpt4 book ai didi

android-layout - 如何强制我的复选框文本不换行?

转载 作者:行者123 更新时间:2023-12-01 09:57:04 25 4
gpt4 key购买 nike

这是我的 LinearLayout(水平)行的样子:

enter image description here

我希望复选框的文本在一行上;按钮不必那么宽 - 它们仍然有足够的空间,复选框文本稍微加长。我的 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>

...需要更改以强制我的复选框文本不换行?

更新

遵循 Der Golem 的建议,添加以下内容:
android:lines="1"

...并且还将复选框的 layout_weight 从 1 更改为 2(按钮设置为 1)给了我我想要的:

enter image description here

最佳答案

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 的评论。

关于android-layout - 如何强制我的复选框文本不换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24048618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com