I'm trying to make a clickable image, however there are many clickable spots over the image. I tho开发者_开发百科ught the best was to create a group of view's that would stay above the image and be clickable.
But I'm having trouble to place them on the right spot.
Does anyone have an idea in how to make this?
Could you instead do something like
imageView.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
// event.getX() and event.getY() give you the co-ordinate
// of the touch, and from that you can work out which thing
// has been touched and so what to do?
}
}
});
?
A stupid relativelayout example, positions three imageviews containing an icon over a TextView with lots of text in it:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/textView1" android:text="TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView " android:layout_alignParentTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<ImageView android:id="@+id/imageView1" android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true"></ImageView>
<ImageView android:id="@+id/imageView2" android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="10dp"></ImageView>
<ImageView android:id="@+id/imageView3" android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="25dp" android:layout_marginTop="35dp"></ImageView>
</RelativeLayout>
Note that z-order is defined by order in the xml so the further down in the file something is, the higher it is in the display.
you need to look into FrameLayout and Z order like the answer to this question here
hope this is what you're looking for!
Apply implement OnClickListener interface to it
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setOnClickListener(new OnClickListener() {
public void onClick(View arg0){
//YOUR CODE HERE
}
})
精彩评论