-3

我需要一个解决方案,如何找到完全适合 ImageView 高度和宽度的任何图像高度和宽度?

4

2 回答 2

1

您可以通过它的drawable获取图像的宽度和高度;

int width = imgView.getDrawable().getIntrinsicWidth();
int height = imgView.getDrawable().getIntrinsicHeight();

如果你想让你的图像适合 ImageView 那么你可以使用

<ImageView
    android:id="@id/img"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY" />

但是你有一个低分辨率的图像,然后它会扭曲。

于 2017-01-23T10:41:56.663 回答
0

如果您希望图像适合图像视图而不会出现图像失真

<ImageView
    android:id="@id/img"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter" />
于 2017-01-23T09:57:05.383 回答