如何使layout_weight固定其宽度

问题描述

如何使它向左对齐?我希望第二列向左对齐。 我使用layout_weight,但是当内容长度不同时,它将更改父视图的宽度

enter image description here

layout.xml


        <LinearLayout
            ...
            android:weightSum="1.1">

            <FrameLayout
                ...
                android:layout_weight="0.5">

                <TextView/>

            </FrameLayout>

            <FrameLayout
                ...
                android:layout_weight="0.3">

                <TextView/>

            </FrameLayout>

            <FrameLayout
                ...
                android:layout_weight="0.3">

                <TextView/>

            </FrameLayout>

        </LinearLayout>

解决方法

这是我的一个例子:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Music"
        android:textSize="20dp"/>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fewwe"
            android:textSize="20dp"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="wfeewf"
            android:textSize="20dp"/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="DasDAS"
            android:textSize="20dp"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="dASfafFADS"
            android:textSize="20dp"/>
    </LinearLayout>
</LinearLayout>

这是结果:

enter image description here

您必须始终放置layout_weight=1并记住layout_width="match_parent"

我希望这个例子可以帮助您解决问题,cya:)