android 图片叠加效果

点击打开链接
2011 - 09 - 29

android 图片叠加效果

 要实现两张图片叠加效果 通过查找资料 发现可以用setLayerInset() 实现

 

package com.twy.test;   
  1.   
  2. import android.app.Activity;   
  3. import android.graphics.Bitmap;   
  4. import android.graphics.BitmapFactory;   
  5. import android.graphics.Canvas;   
  6. import android.graphics.Matrix;   
  7. import android.graphics.Paint;   
  8. import android.graphics.drawable.BitmapDrawable;   
  9. import android.graphics.drawable.Drawable;   
  10. import android.graphics.drawable.LayerDrawable;   
  11. import android.os.Bundle;   
  12. import android.view.ViewGroup.MarginLayoutParams;   
  13. import android.widget.ImageView;   
  14. import android.widget.ImageView.ScaleType;   
  15. import android.widget.LinearLayout;   
  16. import android.widget.LinearLayout.LayoutParams;   
  17.   
  18. public class testDemo extends Activity {   
  19.     private LinearLayout lay;   
  20.   
  21.     /** Called when the activity is first created. */  
  22.     @Override  
  23.     public void onCreate(Bundle savedInstanceState) {   
  24.         super.onCreate(savedInstanceState);   
  25.         setContentView(R.layout.main);   
  26.            
  27.         lay = (LinearLayout) findViewById(R.id.linearLayout1);   
  28.   
  29.         firstLay();   
  30.        
  31.     }   
  32.   
  33.     private void firstLay() {   
  34.         Bitmap mbitmap_c = BitmapFactory.decodeResource(getResources(),   
  35.                 R.drawable.cc);   
  36.         Bitmap mbitmap_b = BitmapFactory.decodeResource(getResources(),   
  37.                 R.drawable.bb);   
  38.         Bitmap mbitmap_e = BitmapFactory.decodeResource(getResources(),   
  39.                 R.drawable.ee);   
  40.         Bitmap mbitmap_f = BitmapFactory.decodeResource(getResources(),   
  41.                 R.drawable.ff);   
  42.            
  43.         Drawable[] array = new Drawable[4];   
  44.         array[0] = new BitmapDrawable(mbitmap_b);   
  45.         array[1] = new BitmapDrawable(mbitmap_c);   
  46.         array[2] = new BitmapDrawable(mbitmap_e);   
  47.         array[3] = new BitmapDrawable(mbitmap_f);   
  48.            
  49.         LayerDrawable la = new LayerDrawable(array);   
  50.         la.setLayerInset(00000);   
  51.         la.setLayerInset(180000);   
  52.         la.setLayerInset(2160000);   
  53.         la.setLayerInset(3240000);   
  54.            
  55.         ImageView img = new ImageView(this);   
  56.         img.setImageDrawable(la);   
  57.            
  58.         lay.addView(img);   
  59.            
  60.     }   
  61. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值