下面是平铺的原图,很小,基本看不出效果
下面是效果图是不是很赞
第一种,在代码中设置
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.top_bg);
BitmapDrawable drawable = new BitmapDrawable(bitmap);
drawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
drawable.setDither(true);
//在为某个view文件设置setBackgroundDrawable
xxxx.setBackgroundDrawable(drawable);
第二中,编写一个xml文件,如下我的xml名字为tiledstripes
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/stripes"
android:tileMode="repeat" />
在调用的地方设置background即可
android:background="@drawable/tiledstripes"