【发布时间】:2014-07-05 12:40:17
【问题描述】:
如果我使用 ImageView ,我可以在我的活动上看到图像,但是当我用画布绘制它时我看不到它。我错过了什么吗?可绘制对象的尺寸为 479px*100px。我可以看到 onDraw 函数是使用其中的断点调用的。
public View getScrollingImage(){
View temp = new View(this){
BitmapDrawable cloud= (BitmapDrawable) MainActivity.this.getResources().getDrawable(R.drawable.cartoon_clouds);
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(cloud.getBitmap(), 0,0, null);
invalidate();
}
};
//ImageView temp = new ImageView(this);
//temp.setImageDrawable(this.getResources().getDrawable(R.drawable.cartoon_clouds));
temp.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,1.0f));
return temp;
}
将其添加到查看方式,
mainLayout.addView(getScrollingImage());
我使用的是 Android 4.0.4。
【问题讨论】:
标签: android android-canvas ondraw