我有两个具有相同方法的自定义视图,当我在其中调用invalidate()
时,它会调用onDraw
方法。我尝试了几种方法,包括this.invalidate()
,但它仍然会调用它。我能想到的唯一方法就是在另一个类中添加一个布尔值来检查它是否在onDraw()
内调用它。
public void showPercentage(double percent, double out){
cropx = (int) percent;
outof = (int) out;
this.invalidate();
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(cropx != 0){
croppedBmp = Bitmap.createBitmap(drawGraph2, 0, 0, (drawGraph2.getWidth()*cropx/100), drawGraph2.getHeight());
canvas.drawBitmap(croppedBmp, 0, 0, new Paint());
croppedBmp.recycle();
System.gc();
Runtime.getRuntime().gc();
}
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//System.out.print to check if its being called
System.out.println("hey");
Bitmap croppedBmp = Bitmap.createBitmap(drawGraph2);
canvas.drawBitmap(croppedBmp, 0, 0, new Paint());
}