方法两种:
首先必须在res/drawable目录下包含一个background.jpg
方法1:在res/drawable中创建一个xml文件(background_repeat.xml)
内容为
- <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:src="@drawable/background"
- android:tileMode="repeat"
- />
然后再Activity的xml中
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@drawable/background_repeat">
方法2:
- imageView = (ImageView)findViewById(R.id.MainA_Iv);
- Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.background);
- BitmapDrawable bd = new BitmapDrawable(bitmap);
- bd.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );
- imageView.setBackgroundDrawable(bd);