小像素图像作为android应用程序的背景图像

小像素图像作为android应用程序的背景图像,android,image,background,styles,Android,Image,Background,Styles,我有4x4px的图像,我想设置和重复,直到它填补了所有分辨率的全屏,当我设置为背景,它被拉伸的图像。 我在main.xml中添加了android:tileMode=“repeat”,以实现我想要的功能,但没有任何更改 最终结果应该是这样的 如何执行此操作?在开始时将图像的缩放类型设置为,然后添加重复模式: android:scaleType="fitStart" 您需要使用android Nine patch工具创建Nine patch图像 或 您也可以创建脱机的 在==>sdk/tool

我有4x4px的图像,我想设置和重复,直到它填补了所有分辨率的全屏,当我设置为背景,它被拉伸的图像。 我在main.xml中添加了
android:tileMode=“repeat”
,以实现我想要的功能,但没有任何更改

最终结果应该是这样的


如何执行此操作?

在开始时将图像的缩放类型设置为,然后添加重复模式:

android:scaleType="fitStart"

您需要使用android Nine patch工具创建Nine patch图像

您也可以创建脱机的

在==>sdk/tools/draw9patch下

双击并运行此文件


希望它能起作用。

对我来说,最好的解决方案是创建一个单独的可绘制文件,并在布局文件中使用它

View view = (View) findViewById(R.id.my_view);
//Repeating background image
Bitmap backgroundImage = BitmapFactory.decodeResource(getResources(),   R.drawable.my_background_image);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), backgroundImage);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);  
view.setBackground(bitmapDrawable);
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/my_img"
    android:tileMode="repeat"
    android:dither="true" />

而不是背景设置为src和check。