Android – duplicate background images are stretched

I have a difficult background texture. I have a 60px by 60px bitmap texture. I want to set it as the background of my layout in repeated block mode. This is the layout XML in RES / layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/dark_texture_background" >

    ...
</RelativeLayout

This is dark_ texture_ Background, in RES / drawable:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/dark_background_texture"
    android:tileMode="repeat" />

dark_ background_ Texture is 60 × 60 pixel image

Therefore, the problem is that the texture image is enlarged while being tiled. I added a red line outside the texture image to accurately view the position of the texture image. The results are as follows:

I also added screen height, width and density according to getresources(). Getdisplaymetrics()

Since the screen width is 480 pixels, the texture image should be repeated 8 times (480 / 60 = 8). On the contrary, it is only 5 ~ 1 / 4. The image is now about 90 pixels and tiled. WTF?

Why is my texture image stretched when I explicitly tell it to repeat?

resolvent:

I'm not sure what raghav means, exactly, but if they change something in ICs, there must be a problem. That is, I'm pretty sure the bitmap images in drawable are assumed to be MDPI and scaled from there (maybe they change this behavior?), which makes sense because your 60px image becomes 90px (60 * 1.5 scale factor)

You can completely avoid scaling. Please remember that the physical size of different densities will be different (although it may not be important for the tiled background). Just put the bitmap into the drawable nodpi folder. Android will use these drawable without scaling regardless of the density

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>