0
我正在玩android編碼,並且我創建了一個使用所有屏幕大小的畫布,我需要一些幫助在此畫布上添加觸摸事件,以便每次有人觸摸畫布時更改顏色。更改畫布顏色觸摸
EDIT 2
我設法在我的佈局中插入一個click事件,但我沒有很好地工作,其只設法畫的第一次。
public class Modetwo_paint extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
ll = (LinearLayout) findViewById(R.id.layout_paint);
ll.setBackgroundColor(Color.BLACK);
ll.setOnClickListener(this);
drawView = new DrawViewSingle(this ,width, height, a[0], r[0], g[0], b[0]); //a, r, g, b, they are arrays of int
ll.addView(drawView);
}
public void onClick(View arg0) {
String s;
switch (arg0.getId()) {
case R.id.layout_paint:
clicks+=1;
if (clicks >= a.length) {
clicks = 0;
}
s = "Teste " + clicks;
Toast.makeText(getApplicationContext(), s , Toast.LENGTH_SHORT).show();
drawView = new DrawViewSingle(this ,width, height, a[clicks], r[clicks], g[clicks], b[clicks]);
ll.addView(drawView);
break;
default:
break;
}
}
}
我DrawViewSingle類
public class DrawViewSingle extends View {
Paint paint = new Paint();
int x;
int y;
int a;
int r;
int g;
int b;
int size;
public DrawViewSingle(Context context, int x, int y, int a , int r, int g, int b) {
super(context);
this.x = x;
this.y = y;
this.a = a;
this.r = r;
this.g = g;
this.b = b;
}
@Override
public void onDraw(Canvas canvas) {
paint.setStrokeWidth(0);
paint.setARGB(a, r, g, b);
canvas.drawRect(0, 0, x, y, paint);
}
}
請補充一點,你有沒有 –
任何代碼的代碼,我不確定你試圖完成什麼,也許這將幫助:HTTP://開發商.android.com/guide/topics/graphics/2d-graphics.html – buczek
嘿傢伙,我添加了一些代碼給我的問題,有人可以幫助我嗎? –