gpt4 book ai didi

android - 如何让ImageView根据固定高度匹配宽度?

转载 作者:行者123 更新时间:2023-11-30 01:37:28 27 4
gpt4 key购买 nike

我有一些图像,必须缩放到普通高度,但宽度不同。我如何在 LinearLayout 中将它们设置为固定高度,以便自动评估它们的宽度以保持它们的纵横比?

我试过:

    <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:src="@drawable/clean"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:src="@drawable/c4"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:src="@drawable/c4"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:src="@drawable/c4"/>

</LinearLayout>

不幸的是,效果与我的预期相去甚远(图像太宽):

Result

最佳答案

这样做,使用 android:scaleType="centerCrop"

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

<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="0.25"
android:scaleType="centerCrop"
android:src="@drawable/clean"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="0.25"
android:scaleType="centerCrop"
android:src="@drawable/c4"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="0.25"
android:scaleType="centerCrop"
android:src="@drawable/c4"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="0.25"
android:scaleType="centerCrop"
android:src="@drawable/c4"/>

</LinearLayout>

关于android - 如何让ImageView根据固定高度匹配宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34944068/

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