新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
三種方法實(shí)現(xiàn)Android平鋪效果
需要實(shí)現(xiàn)平鋪效果,大致有幾下幾種方法。

***種,利用系統(tǒng)提供的api實(shí)現(xiàn):
- Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic);
- //bitmap = Bitmap.createBitmap(200, 30, Config.ARGB_8888);
- BitmapDrawable drawable = new BitmapDrawable(bitmap);
- drawable.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );
- drawable.setDither(true);
- view.setBackgroundDrawable(drawable);
第二種,使用xml來(lái)輕松實(shí)現(xiàn),貌似是4.0以后出現(xiàn)的:
- android:src="../../@drawable/img"
- Android:tileMode="repeat" />
第三種,自己畫(huà)出來(lái):
- 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;
- }
網(wǎng)頁(yè)標(biāo)題:三種方法實(shí)現(xiàn)Android平鋪效果
文章位置:http://m.fisionsoft.com.cn/article/dpeogee.html


咨詢(xún)
建站咨詢(xún)
