Android 防止线性布局将元件从其水平方向的侧面推出

Android 防止线性布局将元件从其水平方向的侧面推出,android,android-linearlayout,android-xml,Android,Android Linearlayout,Android Xml,我有一个方向为水平的线性布局,我不希望我的第一个文本视图推其他视图,这是我的代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools"

我有一个方向为水平的
线性布局
,我不希望我的第一个
文本视图
推其他视图,这是我的代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:weightSum="3"
    android:orientation="horizontal">

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/item_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TEST asdas asd" />

    <TextView
        android:id="@+id/item_qty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1"
        android:text="Qty: 2" />

    <TextView
        android:id="@+id/item_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1"
        tools:text="$100.00"/>

</LinearLayout>

输出 没有那么多的文字,看起来像这样

但当文本增加时,会出现一个问题。。。第一个
TextView
推送所有其他文本视图,我想保留第一个图像的外观如果第一个文本只是增加,我想给它一行,而不是推送相邻的文本


我想您的布局有问题。您正在设置项目的权重,但您将
版面宽度
设置为
包裹内容
,这与
版面权重
相矛盾。因此,我建议如下修改布局(基本上设置
布局\u width=0dp



我希望这有帮助

基本上,如果使用权重,则对于方向垂直的线性布局,必须将布局高度设置为0。而对于水平线性布局,布局宽度为0。

尝试为文本视图赋予权重和填充,以便文本视图不会超出此范围。要在末尾显示虚线,请使用android:ellipsize=“end”android:maxLines=“1”似乎线性布局的环绕高度并没有环绕所有文本,我该怎么包装所有的文本呢?我会尝试在顶部和底部加上一些边距。请让我知道这是否有效。很高兴知道我能帮上忙!祝您编码愉快,保持安全!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3">

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/item_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Some long text that is pushing the other texts to the right and taking up all the spaces!!!" />

    <TextView
        android:id="@+id/item_qty"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Qty: 2" />

    <TextView
        android:id="@+id/item_price"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        tools:text="$100.00" />

</LinearLayout>