I would suggest to make a custom view and draw the image in the onDraw method. Now add a onTouchEvent() function to the view... create listeners for each part of the image touched and return the appropriate listener for the area touched.
your View class would be something like this:
- Code: Select all
class MyVeiw extends Veiw{
TopOnClickListener topListener;
onDraw(Canvas canvas){
canvas.drawBitmap(//your image);
onTouchEvent(MotionEvent event){
flaot x=event.getX();
flaot y=event.getY();
if(//x and y are between specific values that define your region[/color]){
//carry out some event
//or still better: return a listener
// eg: topListener.onClick(this);
// if you want to emulate click and not touch, check if MotionEvent.Action.equals(MotionEvent.ACtionDOWN) and UP lie within the same area and then return the listener event.
}
private interface TopOnClickListener(){
void onClick(View v)
}
public TopOnClickListener setTopOnClickListener(OnTopClickListener l){
this.topListener=l;
}
}
and in your activity:
- Code: Select all
MyView mView=new MyView(this);
mView.setOnTopClickListener(new OnTopClickListener(){
onClick(View V){
// carry out whatever you want to do
});
The tricky bit would be to map all the areas that you want to be clickable.
Do tell me if this method works for you. all the best!