【问题标题】:WordWrap in "connected" LinearLayout do not work“连接的”LinearLayout 中的 WordWrap 不起作用
【发布时间】:2012-08-16 16:54:16
【问题描述】:

我不明白为什么我的示例中的自动换行不起作用。

XML 描述了垂直LinearLayout 的“一行”,它将在运行时填充。 该行由checkbox 后跟两列组成。第一列是一个垂直的LinearLayout,里面有两个TextViews(这里可以换行)。第二列是LinearLayout,只有一个TextView(自动换行不起作用)。

如果第二列的文本增长第一列缩小为一个小的“一个字母”列,第二列不换行他的长文本。但第二个也被定义为使用自动换行......

有人知道这个问题的解决方法吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <RelativeLayout
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/relativeLayout1">
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/checkBox1" />
        <LinearLayout
            android:orientation="vertical"
            android:minWidth="25px"
            android:minHeight="25px"
            android:id="@+id/linearLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/checkBox1"
            android:layout_toLeftOf="@id/linearLayout2">
            <TextView
                android:text="A long long long long text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView1"
                android:singleLine="false" />
            <TextView
                android:text="Small Text"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView2"
                android:singleLine="false" />
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:minWidth="25px"
            android:minHeight="25px"
            android:id="@+id/linearLayout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true">
            <TextView
                android:text="Another long long text... please wrap!!"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView3"
                android:singleLine="false" />
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

【问题讨论】:

    标签: android android-linearlayout word-wrap


    【解决方案1】:

    好吧,您在所有文本视图中都将 android:singleLine 设置为“False”。如果您希望其中一个不换行,请将其设置为“True”

    http://developer.android.com/reference/android/widget/TextView.html

    【讨论】:

    • 它们应该共享整个宽度,因此我对所有都使用了 singleLine=false。我的希望是:如果两列都有“长文本”要显示,那么两者都应该使用自动换行来共享宽度(50/50 左右)。
    • 单行与宽度无关,如果要占满整个宽度需要设置 android:layout_width="match_parent" 并确保父布局一致。单行属性仅表示“是否换行”。请注意,如果您将其设置为 true 并且没有足够的屏幕空间,它将截断字符串。
    • 我已将所有 layout_width 更改为“match_parent”。现在复选框和以下第一列是不可见的。最后(第二)列使用整个宽度。我希望他们共享宽度,所以所有三个部分都应该在一条线上。复选框-ColumnA-ColumnB。如果有用,这些列会包装文本以达到此目标。
    • 你应该阅读这个博客。 thinkandroid.wordpress.com/2010/01/14/…您最初的问题是为什么要换行。该问题的答案是 SingleLine 需要设置为 true 以防止任何换行。
    • 没有。你误解我了。我知道为什么专栏会换行。他们必须换行,所以他们可以共享宽度并显示他们的内容。如果他们不能换行 -> 内容将被切断。他们必须包起来。问题是:只有一个包裹(第一个)!不是都。如果两个包裹都很好!
    猜你喜欢
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多