![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 public void paint() { 2 if (item.laying_mode != 1)//平铺或者充满 3 { 4 new AsyncTask<Void, Void, Void>() { 5 @Override 6 protected Void doInBackground(Void... params) { 7 Looper.prepare(); 8 try { 9 theBitmap = Glide. 10 with(ctxt). 11 load(item.src). 12 asBitmap(). 13 into(fenbianlv[0], fenbianlv[1]). 14 get(); 15 } catch (final ExecutionException e) { 16 Log.e(TAG, e.getMessage()); 17 } catch (final InterruptedException e) { 18 Log.e(TAG, e.getMessage()); 19 } 20 return null; 21 } 22 23 @Override 24 protected void onPostExecute(Void dummy) { 25 if (null != theBitmap) { 26 // The full bitmap should be available here 27 28 BitmapDrawable bd = new BitmapDrawable(Resources.getSystem(),theBitmap); 29 if (item.laying_mode == 0)//充满(默认值,缩放到图片全部充满屏幕 30 { 31 } else if (item.laying_mode == 2)//平铺(从左上开始,一个一个的平铺) 32 { 33 bd.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); 34 } 35 rl.setBackground(bd); 36 } 37 } 38 }.execute(); 39 } 40 else//1:居中(图片按照原始大小,放到屏幕中间) 41 { 42 new AsyncTask<Void, Void, Void>() { 43 @Override 44 protected Void doInBackground(Void... params) { 45 Looper.prepare(); 46 try { 47 String imageUrl = item.src; 48 theBitmap= BitmapFactory.decodeStream((InputStream) new URL(imageUrl).getContent()); 49 } catch (final Exception e) { 50 Log.e(TAG, e.getMessage()); 51 } 52 return null; 53 } 54 55 @Override 56 protected void onPostExecute(Void dummy) { 57 if (null != theBitmap) { 58 iv.setImageBitmap(theBitmap); 59 } 60 } 61 }.execute(); 62 } 63 }
一下三种分别是充满、平铺、居中(按图片原始大小)