让背景小图不是拉伸而是多个重复

让背景小图不是拉伸而是多个重复_第1张图片


message_bg.xml

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

用到该背景的xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/message_bg" >

也可以在java文件中用:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.msg_bg);   
BitmapDrawable bd = new BitmapDrawable(bitmap);   
bd.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );   
bd.setDither(true);   
view.setBackgroundDrawable(bd); 


你可能感兴趣的:(让背景小图不是拉伸而是多个重复)