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

Android 如果我使用.75和.25,为什么布局权重不起作用?,android,android-linearlayout,android-layout-weight,Android,Android Linearlayout,Android Layout Weight,这是我的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" and

这是我的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>
但这是因为:

图像视图不可见,并且
Textview
具有100%的

我设置为
Imageview
的任何值都不会更改

现在,如果我更改文本的值,但是更改一个介于0和.99之间的值 (重量为1的图像视图):

如果我使用.75和.25,这个效果很好,但是如果我设置3和1,它就不起作用了 我希望能够使用您为父级
线性布局定义的最后一个值

通过这样做,您告诉线性布局,子项权重之和的最大权重将为1,但随后您将两个子项的权重都设置为1,这等于2


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

您已经在LinearLayout上设置了
android:weightSum=“1”
。要么将其更改为实际金额,要么将其删除。
<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>
android:layout_weight="1"