Android ImageView: How to prevent scaling with ScaleType.CENTER?
According to the docs, using the CENTER attribute will not perform any scaling on the image. Yet, when loading a PNG via XML like shown below, it appears significantly larger than it should be.
开发者_JAVA百科What's going on?
I figure the image is being scaled when it's loaded, but why? Is there some manifest tag missing, or should I be using a different folder?
<ImageView
android:src="@drawable/auth_logo"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:scaleType="center"></ImageView>
Any help would be appreciated.
Scaling of image is caused by difference between your image's DPI and screen DPI. Android manages scaling so that DPI matches.
Image's DPI is determined by res source folder where image is stored (drawable / drawable-hdpi / etc), and actual screen density, which is given physically and is fixed for given device.
To avoid scaling, put your image into res/drawable-nodpi folder.
精彩评论