我正在尝试实现一个在imageview收到longclick时调用全屏图像查看器活动的imageview。代码和imageview的xml声明如下。如果按住图像,图像查看器活动将按照我的预期启动,如果图像被短暂点击则无效,也如我所料。但是,如果我按下图像然后在短暂停顿后将其释放,则全屏图像查看器活动将打开两次。提前感谢您的建议。
try {
// get input stream
String path = "MyData/MyImages/" + myClass.getRESOURCE();
ins = getAssets().open(path);
// load image as Drawable
Drawable d = Drawable.createFromStream(ins, null);
// set image to ImageView
theImage.setImageDrawable(d);
theImage.setVisibility(View.VISIBLE);
theImage.setOnLongClickListener(new View.OnLongClickListener() {
//@Override
public boolean onLongClick(View v) {
Intent intent = new Intent(startActivity.this, MultiTouchActivity.class);
startActivity(intent);
return true;
}
});
}
catch (IOException ex) {
Log.e("whoops", ""+ex);
}
finally {
//close input
if (ins != null) {
try {
ins.close();
}
catch (IOException ioex) {
//Very bad things just happened... handle it
}
}
}
}
<ImageView
android:id="@+id/imageView1"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:layout_alignParentStart="false"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="@drawable/square"
android:hapticFeedbackEnabled="false"
android:visibility="gone"/>