OnClickListener在其他Intent / Fragment中以全屏显示ImageView

时间:2015-04-29 10:18:37

标签: java android android-fragments android-activity imageview

我正在使用片段,我想在另一个视图或对话框中显示 imageView 我的片段中的缩略图?< / strong>或用于显示的内容:)

我希望当我们点击ImageView时,会显示新视图,当我们点击Button时,会返回主片段。

我已经实现了我的onClickListener,这样可行,但我不知道如何传输数据或者全屏显示ImageView ...

这是我的onClickListener代码:

    mImageReport.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (zoomOut) {

                zoomOut = false;
            } else {

                zoomOut = true;
            }
        }
    });

2 个答案:

答案 0 :(得分:0)

无需创建用于显示全屏图像的新窗口。您可以使用Android默认图库图像查看器。只需将完整的图像路径或图像URI设置为“mImageReport”作为标记,在其onClick中您可以检索它。使用以下代码行将全屏图像显示为

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */

答案 1 :(得分:0)

您可以设置全屏对话框以显示如下图像

   final Dialog nagDialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
        nagDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        nagDialog.setCancelable(false);
        nagDialog.setContentView(R.layout.preview_image);
        Button btnClose = (Button)nagDialog.findViewById(R.id.btnIvClose);
        ImageView ivPreview = (ImageView)nagDialog.findViewById(R.id.iv_preview_image);
        ivPreview.setBackgroundDrawable(dd);

        btnClose.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {

                nagDialog.dismiss();
            }
        });
        nagDialog.show();

包含图像视图和关闭按钮的布局的xml代码:

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ImageView android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/iv_preview_image" />


<Button android:layout_width="wrap_content"
    android:layout_height="wrap_content"   android:background="@drawable/close"
    android:id="@+id/btnIvClose" android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" />