本文實例講述了Android編程實現圖片平鋪的方法。分享給大家供大家參考,具體如下:
1)第一種利用系統提供的api實現
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來輕松實現
<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;}更多關于Android相關內容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結》、《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
新聞熱點
疑難解答