欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android實現(xiàn)背景平鋪的三種方法

 更新時間:2014年02月28日 16:07:50   作者:  
這篇文章主要介紹了Android的圖片平鋪效果的實現(xiàn)方法,主要有使用系統(tǒng)API、使用XML配置、自定義繪制三種方法,需要的朋友可以參考下

方法1: 系統(tǒng)api實現(xiàn)

復制代碼 代碼如下:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic); 
//bitmap = Bitmap.createBitmap(100, 20, Config.ARGB_8888); 
BitmapDrawable drawable = new BitmapDrawable(bitmap); 
drawable.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT ); 
drawable.setDither(true); 
view.setBackgroundDrawable(drawable);

方法2: XML實現(xiàn)

xml路徑:res/drawable/bg.xml

復制代碼 代碼如下:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"  
    android:src="@drawable/img" 
    android:tileMode="repeat" /> 

方法3: 自定義繪制

復制代碼 代碼如下:

public static Bitmap createRepeater(int width, Bitmap src){ 
  int count = (width + src.getWidth() - 1) / src.getWidth(); 
  Bitmap bitmap = Bitmap.createBitmap(width, src.getHeight(), Config.ARGB_8888); 
  Canvas canvas = new Canvas(bitmap); 

  for(int idx = 0; idx < count; ++ idx){ 
    canvas.drawBitmap(src, idx * src.getWidth(), 0, null); 
  } 

  return bitmap; 
}

相關文章

最新評論