当图像上发生触摸事件时,我正在尝试添加图像按钮。使用 ImageView 显示图像。但是当我触摸图像时没有任何反应。此处附上代码
快速.java
ImageView myImageView = (ImageView)findViewById(R.id.imgView);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.india_map);
myImageView.setImageBitmap(bitmap);
myImageView.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
ImageButton imgbutton=(ImageButton)findViewById(R.id.imageButton1);
Bitmap image = BitmapFactory.decodeResource(getResources(),R.drawable.image5);
imgbutton.setImageBitmap(image);
imgbutton.setVisibility(View.VISIBLE);
return false;
}
});
activity_quick.xml
<LinearLayout
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<ImageView
android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:contentDescription="@string/desc"
android:src="@drawable/india_map"/>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image5"
android:contentDescription="@string/desc"
android:visibility="invisible" />
</LinearLayout>
请帮我解决这个问题