中心绘制和规模高度 [英] Center drawable and scale height
问题描述
由于我要支持平板电脑和智能手机而不释放一个特殊的HD版,我需要根据用户设备的分辨率缩放我的图片。这是一个看起来对三星Galaxy Nexus的好ImageView的来源:
Since I want to support tablets and smartphones without delivering a special "HD" version, I need to scale my Images depending on the resolution of the users device. This is the ImageView source that looks good on the Samsung Galaxy Nexus:
<ImageView
android:id="@+id/character"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:scaleType="centerCrop"
android:src="@drawable/ma_un1_001" />
但是,将削减对的Nexus 7的图像。
But it will cut the image on the nexus 7.
当我改变的宽度和高度为:
When I changed the width and height to:
<ImageView
android:id="@+id/character"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="@android:color/transparent"
android:scaleType="centerCrop"
android:src="@drawable/ma_un1_001" />
不幸的是这将缩放图像出来的观点:
Unfortunately this scales the image out of the view:
修改XML以
android:layout_width="wrap_content"
android:layout_height="fill_parent"
仍然会削减图像。
Would still cut the image.
于是我改变了scaleType到FIT_START
So I changed the scaleType to FIT_START
<ImageView
android:id="@+id/character"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="@android:color/transparent"
android:scaleType="fitStart"
android:src="@drawable/ma_un1_001" />
看起来对我的所有设备都很大,但绘制的左对齐。
有什么办法来居中?
Looks great on all my devices, but the drawable is aligned to the left. Is there any way to center it?
推荐答案
感谢文辉我找到了解决办法。
Thanks to Wenhui I found the solution.
<ImageView
android:id="@+id/character"
**android:layout_width="fill_parent"
android:layout_height="fill_parent"**
android:layout_alignParentBottom="true"
android:background="@android:color/transparent"
**android:scaleType="fitCenter"**
android:src="@drawable/ma_un1_001" />
缩放图像的每一个屏幕尺寸,并不会削减任何东西。非常感谢你。
Scales the Image to every screensize and won't cut anything. Thank you very much.
这篇关于中心绘制和规模高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!