来自OnDraw的Android Draw ImageViiew

时间:2011-04-20 04:04:36

标签: android android-layout

Hi

如何从OnDraw()方法中绘制ImageView? canvas。()不必调用资源吗?

我正在尝试这样做

    @Override    
   protected void onDraw(Canvas canvas) {         
          super.onDraw(canvas);        
         imageBack = BitmapFactory.decodeResource(getResources(), R.drawable.background);             

     canvas.drawBitmap(imageBack, (x /2)-15 ,y /2, null);          
   //touchEvents();        
     ImageView image1 = (ImageView)findViewById(R.id.ImageView01); 
   }  

1 个答案:

答案 0 :(得分:0)

您需要将ImageView转换为位图

ImageView image1 = (ImageView)findViewById(R.id.ImageView01); 
    image1.buildDrawingCache();
    Bitmap bmap = image1.getDrawingCache();

然后您可以绘制bmap