想要一个动态大小的ImageView Android

问题描述 投票:-1回答:1

我想要一个 ImageView 将其高度设置为 340dp 和宽度为 wrap_content 当高度大于宽度,当宽度大于高度时,它将高度设置为 wrap_content 其宽度为 400dp.

我想实现所有这些,并保持长宽比。

先谢谢你了,我想要一个ImageView,当高度大于宽度时,将高度设置为340dp,宽度设置为wrap_content。

android android-imageview android-bitmap
1个回答
0
投票
  1. 你可以设置你的 ImageView的布局尺寸,通过指定android:layout_widthandroid:layout_height.
  2. 要保持你的图像的纵横比加载到你的布局范围内,你的 ImageView,您可以设置 android:scaleTypefitCenter.

所以,你的 ImageViewlayout.xml 可以定义为像吹。

<ImageView
        android:scaleType="fitCenter"
        android:layout_width="400dp"
        android:layout_height="340dp"
        (...)
        />
© www.soinside.com 2019 - 2024. All rights reserved.