如何强制复选框的文本不自动换行? [英] How can I force my checkbox's text to not wrap?

查看:560
本文介绍了如何强制复选框的文本不自动换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is what my LinearLayout (horizontal) row looks like:

我希望复选框的文本在一行上;按钮不必那么宽-复选框文本加长了一点,它们仍然有足够的空间.我的XML中有什么:

I want the text of the checkbox to be on one line; The buttons don't have to be that wide - they'll still have plenty of space with the checkbox text lengthened a bit. What in my 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>

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

...needs to change in order to force my checkbox text not to wrap?

按照Der Golem的建议添加以下内容:

Following Der Golem's suggestion by adding this:

android:lines="1"

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

...and also changing layout_weight for the checkbox from 1 to 2 (set to 1 for the buttons) gave me what I wanted:

推荐答案

CheckBox继承自CompoundButton,CompoundButton继承自Button,Button继承自 TextView .因此,它具有这些祖先 ...
的所有属性,方法和属性. 参考: http://developer.android.com/reference/android/widget/CheckBox .html

CheckBox inherits from CompoundButton, which inherits from Button, which inherits from TextView. So, it has all the properties, methods and attributes of these ancestors...
Reference: http://developer.android.com/reference/android/widget/CheckBox.html

尤其,您对 TextView 属性,方法和属性感兴趣:
参考: http://developer.android.com/reference/android/widget/TextView .html

In particular, you are interested to the TextView properties, methods and attributes:
Reference: http://developer.android.com/reference/android/widget/TextView.html

尤其是,您对android:lines属性感兴趣,并将其设置为 1 .
这表明您的CheckBox高度精确为1行.

In particular, you're interested in the android:lines attribute, and set it to 1.
This tells your CheckBox to be exactly 1 line tall.

您可能还希望将android:ellipsize属性设置为某个值(即:3 =结束).
这告诉您的CheckBox在截断的文本的末尾,开始,中心,...处添加三个点(省略号).

You might also want to set the android:ellipsize attribute to some value (i.e.: 3 = end).
This tells your CheckBox to add three dots (ellipsis) to the end, start, center, ... of the truncated text.

作为TextView的代表,它可以使用setSingleLine-感谢@CrandellWS的评论.

Being a decentant of TextView, it can use setSingleLine - Thanks to @CrandellWS for the comment.

这篇关于如何强制复选框的文本不自动换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆