自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

三種方法實(shí)現(xiàn)Android平鋪效果

移動(dòng)開發(fā) Android
這里提供了三種方法實(shí)現(xiàn)Android平鋪效果,分別是利用系統(tǒng)提供的api實(shí)現(xiàn)、使用xml來輕松實(shí)現(xiàn)和自己畫出來。

需要實(shí)現(xiàn)平鋪效果,大致有幾下幾種方法。

***種,利用系統(tǒng)提供的api實(shí)現(xiàn):

  1. Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic); 
  2.  
  3. //bitmap = Bitmap.createBitmap(200, 30, Config.ARGB_8888); 
  4. BitmapDrawable drawable = new BitmapDrawable(bitmap); 
  5. drawable.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT ); 
  6. drawable.setDither(true); 
  7. view.setBackgroundDrawable(drawable);  

 第二種,使用xml來輕松實(shí)現(xiàn),貌似是4.0以后出現(xiàn)的:

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

第三種,自己畫出來:

  1. public static Bitmap createRepeater(int width, Bitmap src){ 
  2. int count = (width + src.getWidth() - 1) / src.getWidth(); 
  3.  
  4. Bitmap bitmap = Bitmap.createBitmap(width, src.getHeight(), Config.ARGB_8888); 
  5. Canvas canvas = new Canvas(bitmap); 
  6.  
  7.     for(int idx = 0; idx < count; ++ idx){ 
  8.         canvas.drawBitmap(src, idx * src.getWidth(), 0null); 
  9.      } 
  10.  
  11.      return bitmap; 
  12. }  

 

責(zé)任編輯:徐川 來源: OSChina
相關(guān)推薦

2021-07-13 12:31:27

IT組織改進(jìn)首席技術(shù)官

2009-07-08 12:56:32

編寫Servlet

2010-09-06 10:04:31

CSS樣式表

2011-06-10 10:43:12

Ubuntu應(yīng)用安裝

2009-06-23 10:45:18

Hibernate支持

2010-09-30 15:37:29

ScrollBarJavascrip

2015-12-11 09:24:38

加密數(shù)據(jù)Linux

2010-08-26 16:19:41

DIV圓角

2009-12-11 18:49:39

預(yù)算編制博科資訊

2022-07-13 16:06:16

Python參數(shù)代碼

2011-04-18 15:32:45

游戲測(cè)試測(cè)試方法軟件測(cè)試

2010-09-14 15:10:49

CSS注釋

2023-08-14 17:58:13

RequestHTTP請(qǐng)求

2024-11-15 07:00:00

Python發(fā)送郵件

2024-07-31 20:38:18

2012-06-20 13:46:23

CSS

2015-12-30 09:58:49

Docker Comp容器

2016-06-12 09:32:43

R語言Hadoop數(shù)據(jù)處理

2022-09-13 10:58:55

物聯(lián)網(wǎng)IoT

2020-06-17 10:52:00

DDoS攻擊網(wǎng)絡(luò)攻擊網(wǎng)絡(luò)安全
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)