使用一个小图片tile平铺到ImageView中或Activity背景

方法两种:

 

首先必须在res/drawable目录下包含一个background.jpg

方法1:在res/drawable中创建一个xml文件(background_repeat.xml)

              内容为

 

[html] view plaincopy
 
  1. <bitmap xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:src="@drawable/background"  
  3.     android:tileMode="repeat"  
  4. />  



 

然后再Activity的xml中

 

[html] view plaincopy
 
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:orientation="vertical"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:background="@drawable/background_repeat">  



 

方法2:

 

[java] view plaincopy
 
  1. imageView = (ImageView)findViewById(R.id.MainA_Iv);  
  2. Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.background);  
  3.   
  4. BitmapDrawable bd = new BitmapDrawable(bitmap);  
  5. bd.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );  
[java] view plaincopy
 
    1. imageView.setBackgroundDrawable(bd);  
posted @ 2015-08-11 16:29  dongweiq  阅读(1216)  评论(0编辑  收藏  举报