假设你有这个
<ImageView
android:id="@+id/mainImageView"
android:layout_width="match_parent"
android:background="@drawable/mylogo_250px60px"
/>
我想定义高度,以便它根据宽度进行缩放。因此,如果 Android 决定缩放 Logo 以显示宽度,则高度也应增加。
是否也可以定义一些东西,以便当手机从垂直倾斜到水平时, Logo 会正确缩放?
(基本上, Logo 位于主要 Activity 的 ListView 上方)
我也尝试过使用它,但运气不好(与宽度相比,高度显得低得多。图像的高度未调整/缩放)
<ImageView
android:id="@+id/mainImageView"
android:layout_width="match_parent"
android:background="@drawable/mylogo_250px60px"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:adjustViewBounds="true"
/>
如果我在 Eclipse/ADT gui 工具中设计它, Logo 将达到 76dp,并且在我的两部测试手机上看起来不错。但是,我认为应该可以简单地适本地缩放图像?
“固定高度”具有正确的宽度比例(垂直 View ,不是手机倾斜时)
“自动高度”与宽度相比,比例错误:
最佳答案
如下更改您的 imageview 代码
<ImageView
android:id="@+id/mainImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/mylogo_250px60px"
android:scaleType="fitEnd"
android:adjustViewBounds="true"
/>
关于android - 在 Android 中按比例调整 ImageView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15966623/