如果我使用 .75 和 .25,为什么布局权重不起作用?

Why is layout weight not working if I use .75 and .25?

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:weightSum="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="8 diciembre, 2015"
        android:id="@+id/txtFecha"
        android:textAlignment="textEnd"
        android:layout_margin="5dp"
        android:layout_gravity="right" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1"
        android:layout_margin="10dp">

        <TextView
            android:layout_width="0dp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text"
            android:id="@+id/txtTituloNot"
            android:layout_height="wrap_content"
            android:maxHeight="52dp"
            android:layout_weight="1" />

        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/imageView"
            android:src="@drawable/feclaabajo"
            android:layout_below="@+id/txtTituloNot"
            android:scaleType="fitXY"
            android:adjustViewBounds="false"
            android:layout_weight="1" />

    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text Medium Text Medium Text Medium Text
        Medium Text Medium Text Medium Text Medium Text Medium Text
        Medium Text Medium Text Medium Text Medium Text Medium Text
        Medium Text Medium Text Medium Text Medium Text Medium Text Medium"
        android:id="@+id/txtExtracto"
        android:layout_margin="5dp"
        android:maxHeight="110dp"
        android:layout_height="wrap_content" />

    <ImageView
        android:layout_width="233dp"
        android:layout_height="170dp"
        android:id="@+id/imageViewNoticia"
        android:src="@drawable/imagenodisponible"
        android:soundEffectsEnabled="false"
        android:layout_gravity="center_horizontal"
        android:scaleType="fitXY"
        android:layout_marginBottom="7dp" />

</LinearLayout>

但现在我只使用以下代码:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="1"
    android:layout_margin="10dp">

    <TextView
        android:layout_width="0dp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text"
        android:id="@+id/txtTituloNot"
        android:layout_height="wrap_content"
        android:maxHeight="52dp"
        android:layout_weight="1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/feclaabajo"
        android:layout_below="@+id/txtTituloNot"
        android:scaleType="fitXY"
        android:adjustViewBounds="false"
        android:layout_weight="1" />

</LinearLayout>

如您所见,imageview 和 textview 具有:

android:layout_weight="1"

但这就是它:

图片浏览没看到,Textview有100%

我设置的任何值Imageview这不会改变

现在,如果我将文本的值更改为 0 到 .99 之间的值 (图像视图但重量为 1):

如果我使用 .75 和 .25 效果很好,但如果我设置 3 和 1 则效果不佳 我希望能够使用最后一个

您已经为父 LinearLayout 定义了一个 weightSum 为 1 的 weightSum

通过这样做,您告诉 LinearLayout 子项权重总和的最大权重将为 1,但是随后您将两个子项的权重设置为 1,总计为 2。

最简单的解决方案是简单地删除 weightSum 属性,因为在这种情况下没有必要,这样您就不必记得保持同步。