Android:LinearLayout(水平)切断最后一列

Android:LinearLayout(水平)切断最后一列,android,android-linearlayout,Android,Android Linearlayout,非常简单的布局: 我有两个文本视图显示在一行中。布局在屏幕上居中,两个字符串以编程方式设置,第一个字符串为可变长度字符串,第二个字符串为空或(比如)“X”: 请注意,第一个TextView被省略,以便在字符串的大小超过TextView时切断字符串。 我预计会出现以下情况: “普通文本| X”(在屏幕上居中) “超大文本必须为…| X”(以屏幕为中心-填充屏幕) 但实际情况是:第一个文本视图省略,但填充整个屏幕(-width),第二个文本视图脱离屏幕(分别包装到下一行)。 使用“重量”并没有任

非常简单的布局: 我有两个文本视图显示在一行中。布局在屏幕上居中,两个字符串以编程方式设置,第一个字符串为可变长度字符串,第二个字符串为空或(比如)“X”:


请注意,第一个TextView被省略,以便在字符串的大小超过TextView时切断字符串。 我预计会出现以下情况:

“普通文本| X”(在屏幕上居中)

“超大文本必须为…| X”(以屏幕为中心-填充屏幕)

但实际情况是:第一个文本视图省略,但填充整个屏幕(-width),第二个文本视图脱离屏幕(分别包装到下一行)。 使用“重量”并没有任何帮助。将布局高度设置为固定值(例如15dp)也无济于事

有什么建议吗?


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:orientation="horizontal"
    android:layout_gravity="center_horizontal"
     >

    <TextView
        android:id="@+id/lblSelectionName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="asdhsagdkgfhgfhghg"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/lblSelectionAttribute"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="X"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

感谢您的快速响应,但正如我前面提到的……设置权重并没有真正的帮助,因为设置weight=“1”和with=“0”会导致:“普通文本| X”“超大文本…”在这两种情况下,布局占据整个屏幕宽度,并将第一个文本视图放在最左边,第二个放在最右边的可用空间。。。我尝试了重力(第一个文本视图为“右”,第二个文本视图为“左”)。没有帮助…编辑答案,在LinearLayout中使用layout_gravity而不是gravity!(Half:o)由于某些原因,在设置TextView的文本后,布局不会被布局。也就是说:第一次设置文本时,它看起来像“普通文本| X”,在将文本更改为“超大…”后,布局采用相同的边界,这将导致TextView将大部分内容省略为“早期”…它看起来像:“超大…”X。我在文本视图上调用“forceLayout()”,一切都很好!非常感谢,阿伦!
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:orientation="horizontal"
    android:layout_gravity="center_horizontal"
     >

    <TextView
        android:id="@+id/lblSelectionName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="asdhsagdkgfhgfhghg"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/lblSelectionAttribute"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="X"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>