开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜