带有layout_weight属性和src的imageView无法适应给定的大小



当我尝试在具有layout_weight和图像的LinearLayout中使用ImageView时,ImageView会占据整个空间。

假设我有这样的布局:

<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="10">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/blue"/>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="8"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:background="@color/red"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/green"/>
</LinearLayout>

布局(屏幕)如下:

(信誉不足,无法发布图片,抱歉)

////////

蓝色线条布局(主布局的1/10)

////////

RED ImageView(主布局的8/10)

////////

绿色线形布局(主布局的1/10)

////////


但是如果我在ImageView:中添加一个图像(大的…)

<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="10">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/blue"/>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="8"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:background="@color/red"
        android:src="@drawable/splash"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/green"/>
</LinearLayout>

它看起来像这样:

////////

RED ImageView(主布局的10/10)-带图像。。。。。

////////

任何人都知道我如何使ImageView的src适合给定的空间(主LinearLayout的8/10)谢谢

显然这是安卓工作室预览版的问题(安卓API 19级之前)

当部署到设备时,它工作得很完美。。。。

最新更新