开发者

Android ImageView: How to prevent scaling with ScaleType.CENTER?

开发者 https://www.devze.com 2023-04-09 16:19 出处:网络
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.开发者_

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

精彩评论

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

关注公众号