即时通讯开发一个应用程序,它具有上选择特定的图像作为索引图像该活动将开始,但我不知道如何设置onClickListener或onTouchListener在画布我的继承人code
Im developing an application which having Images as a Index on selection of particular image that activity will begin but I dont know how to set onClickListener or onTouchListener in Canvas heres my code
public class DrawView extends View implements OnTouchListener {
LinearLayout mLayout;
Bitmap index;
Bitmap book;
Bitmap bird;
Bitmap game;
Bitmap mail;
Bitmap music;
Bitmap torch;
Paint paint;
public DrawView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
index = BitmapFactory.decodeResource(getResources(), R.drawable.photo1);
book = BitmapFactory.decodeResource(getResources(), R.drawable.book);
game = BitmapFactory.decodeResource(getResources(), R.drawable.game);
music = BitmapFactory.decodeResource(getResources(), R.drawable.music);
}
public void onDraw(Canvas canvas){
paint = new Paint();
Bitmap indexcanvas = Bitmap.createScaledBitmap(index, canvas.getWidth(),
canvas.getHeight(), true);
canvas.drawBitmap(indexcanvas, 0, 0, paint);
canvas.drawBitmap(book, 160, 100, paint);
canvas.drawBitmap(game, 30, 10, paint);
canvas.drawBitmap(music, 80, 50, paint);
}
public boolean onTouch(View v, MotionEvent event) {
return false;
}
请,如果有人知道如何添加onClickListener为特定的图像,例如在这里,如果我点击书,然后bookActivity将启动。
Please if anyone knows how to add onClickListener for particular image e.g. here if I click on Book then bookActivity will start.
尝试是这样的:
public boolean onTouch(View v, MotionEvent event) {
if((event.getX(0)>=160) &&
(event.getY(0)>=100) &&
( event.getX(0)<=160+BOOK_IMG_WIDTH) &&
(event.getY(0)<=100+BOOK_IMG_HEIGHT))
{
//book selected
}
return true;
}
上一篇:最好的方式来存储SparseBooleanArray的包?最好的、方式、SparseBooleanArray
下一篇:如何存储和检索(键,值)使用节省preferences的Android样的数据节省、数据、Andr、preferences