mình muốn sau khi gọi hàm invalidate() thì phương thức ondraw lập tức thực thi ngay rồi mới chạy tiếp các đoạn code sau nó, đây là đoạn code của mình mong mọi người giúp đỡ.
Mã:
public class player extends view {
int state;
public player(context context) {
super(context);
// todo auto-generated constructor stub
state = 0;
}
@override
protected void ondraw(canvas canvas) {
// todo auto-generated method stub
super.ondraw(canvas);
paint paint = new paint();
canvas.drawbitmap(loadres(r.drawable.setting_backbround_player), 0, 0,
paint);
if (state == 1) {
canvas.drawbitmap(loadres(r.drawable.o_3), 100, 650, paint);
}
if (state == 2) {
canvas.drawbitmap(loadres(r.drawable.x_3), 430, 650, paint);
}
}
@override
public boolean ontouchevent(motionevent event) {
// todo auto-generated method stub
if (check_rect(30, 110, 420, 532, event.getx(), event.gety())) {
state = 1;
invalidate();
}
state = 2;
invalidate();
return super.ontouchevent(event);
}
public bitmap loadres(int index) {
bitmap temp;
temp = bitmapfactory.decoderesource(getresources(), index);
return temp;
}
public boolean check_rect(int left, int top, int width, int height,
float x, float y) {
if ((x >= left) && (x <= (left + width)) && (y >= top)
&& (y <= (top + height)))
return true;
return false;
}
}
Dự án căn hộ The Emerald Garden View xây dựng bởi Lê Phong Group không gian đẳng cấp cạnh trung tâm đảm bảo an toàn. dự án The Emerald Garden View không gian đẳng cấp nhiều sức hút tiện nghi vượt...
The Emerald Garden View Khu đô thị tâm điểm giao thông giao thông tốt