gpt4 book ai didi

android - 具有 layout_weight 属性和 src 的 imageView 无法适应给定的尺寸

转载 作者:行者123 更新时间:2023-11-30 02:34:36 25 4
gpt4 key购买 nike

当我尝试在具有 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>

布局(屏幕上)如下所示:

(声望不足,无法发布图片,抱歉)

////////

BLUE LinearLayout(主布局的 1/10)

////////

RED ImageView(主布局的 8/10)

////////

绿色LinearLayout(主布局的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)谢谢。

最佳答案

显然这是 android studio 预览版的问题(在 android API 级别 19 之前)

当部署到设备上时,它运行完美......

关于android - 具有 layout_weight 属性和 src 的 imageView 无法适应给定的尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26778243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com