我尝试在对话框中使用imageViewTouch实用程序,但不显示图像,从imageviewtouch更改为常见的imageview,图像显示正确...
imageViewTouch实用程序: http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/ https://github.com/sephiroth74/ImageViewZoom
以下是对话框调用的代码:
originalImage.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("DisplayImage", "onDoubleTap");
DisplayOneImage doi=new DisplayOneImage(DisplayImage.this,"Original Image");
doi.show();
// Intent intent = new Intent(getApplicationContext(),DisplayOneImage.class);
// startActivity(intent);
return true;
}
});
以下是显示图片的对话框的代码:
public class DisplayOneImage extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public Dialog d;
String itd;
ImageViewTouch OneImage;
String mypath = null;
InputStream xsi1 = null;
Bitmap xbitmap1;
LinearLayout disp_img;
public DisplayOneImage(Activity a, String imageToBeDisplayed) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
itd = imageToBeDisplayed;
Log.i("DisplayOneImage", "2");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i("DisplayOneImage", "1");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.display_one_image);
OneImage = (ImageViewTouch) findViewById(R.id.photo);
OneImage.setDisplayType(DisplayType.FIT_IF_BIGGER);
File root = Environment.getExternalStorageDirectory();
Log.i("DisplayOneImage", "3");
if (itd == "Original Image") mypath = "mydata.bmp";
if (itd == "Image 1") mypath = "mydatazzz.bmp";
Log.i("DisplayOneImage", "4");
File xfile = new File(root.getAbsolutePath() + "/DSP2Android/" + "mydata.bmp");
Log.i("DisplayOneImage", "5");
if (xfile.exists()) {
try {
xsi1 = new FileInputStream(root.getAbsolutePath() + "/DSP2Android/" + "mydata.bmp");
Log.i("DisplayOneImage", "File is found");
Log.i("DisplayOneImage", "6");
xbitmap1 = BitmapFactory.decodeStream(xsi1);
Log.i("DisplayOneImage", "Streamer created");
OneImage.setImageBitmap(xbitmap1, null, -1, -1);
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("DisplayOneImage", "Fault");
}
} else {
disp_img = (LinearLayout) findViewById(R.id.img_original);
disp_img.setVisibility(disp_img.GONE);
}
// originalImage = (ImageViewTouch) findViewById(R.id.initial_photo);
// originalImage.setImageBitmap(BitmapFactory.decodeStream(si1));
OneImage.setSingleTapListener(
new OnImageViewTouchSingleTapListener() {
@Override
public void onSingleTapConfirmed() {
Log.d("DisplayOneImage", "onSingleTapConfirmed");
}
}
);
OneImage.setDoubleTapListener(
new OnImageViewTouchDoubleTapListener() {
@Override
public void onDoubleTap() {
Log.d("DisplayOneImage", "onDoubleTap");
}
}
);
OneImage.setOnDrawableChangedListener(
new OnDrawableChangeListener() {
@Override
public void onDrawableChanged(Drawable drawable) {
Log.i("DisplayOneImage", "onBitmapChanged: " + drawable);
}
}
);
}
@Override
public void onClick(View v) {
dismiss();
}
}
以下是对话框的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#3E80B4"
android:orientation="vertical" >
<!--ImageView
android:id="@+id/initial_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/-->
<com.apps.gv.library.imagezoom.utils.ImageViewTouch
android:id="@+id/photo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
这里有一些我用作标记的日志:
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3b3e76f9 time:5306909
E/CliptrayUtils: hideClipTrayIfNeeded() TextView is focused!! hideClipTray()
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
D/DisplayImage: onDoubleTap
I/DisplayOneImage: 2
I/DisplayOneImage: 1
I/PhoneWindow: [generateLayout] setColorNavigationBar => color=0x ff000001
D/PhoneWindowEx: [LMJ][PWEx][generateLayout] setNavigationBarColor2 : colors=0xff000000
I/PhoneWindow: [setNavigationBarColor2] color=0x ff000000
I/DisplayOneImage: 3
I/DisplayOneImage: 4
I/DisplayOneImage: 5
I/DisplayOneImage: File is found
I/DisplayOneImage: 6
I/DisplayOneImage: Streamer created
D/DisplayImage: onDoubleTap
I/DisplayOneImage: 2
I/DisplayOneImage: 1
I/PhoneWindow: [generateLayout] setColorNavigationBar => color=0x ff000001
D/PhoneWindowEx: [LMJ][PWEx][generateLayout] setNavigationBarColor2 : colors=0xff000000
I/PhoneWindow: [setNavigationBarColor2] color=0x ff000000
I/DisplayOneImage: 3
I/DisplayOneImage: 4
I/DisplayOneImage: 5
I/DisplayOneImage: File is found
I/DisplayOneImage: 6
I/DisplayOneImage: Streamer created
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
D/DisplayImage: onDoubleTap
I/DisplayOneImage: 2
I/DisplayOneImage: 1
I/PhoneWindow: [generateLayout] setColorNavigationBar => color=0x ff000001
D/PhoneWindowEx: [LMJ][PWEx][generateLayout] setNavigationBarColor2 : colors=0xff000000
I/PhoneWindow: [setNavigationBarColor2] color=0x ff000000
I/DisplayOneImage: 3
I/DisplayOneImage: 4
I/DisplayOneImage: 5
I/DisplayOneImage: File is found
I/DisplayOneImage: 6
I/DisplayOneImage: Streamer created
另一件我不明白的事情是,即使我只点击一次图像以激活对话框,似乎多次调用对话框...... (但我认为这可能不是问题的原因)
答案 0 :(得分:1)
在自定义对话框类
上执行此操作 ViewGroup.LayoutParams params = getWindow().getAttributes();
params.width = LinearLayout.LayoutParams.MATCH_PARENT;
getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);