简体   繁体   English

试图在Dialog中将ImageView设为完整大小不起作用

[英]Trying to make ImageView full size in Dialog doesn't work

I'm using Fragments , I would like to get full size image mImageReport when I tap on ImageView on my fragment. 我正在使用Fragments ,当我在片段上点击ImageView时,我想获取全尺寸的图像mImageReport My second layout is test.xml (for Dialog). 我的第二个布局是test.xml(用于Dialog)。

I'm getting image from URL using Picasso 我正在使用Picasso从URL获取图像

But the problem is my image doesn't appear on the new dialog (mImageReport). 但是问题是我的图像没有出现在新对话框(mImageReport)中。 I don't know how to link the imageView from test.xml with the image I want in full screen in my fragment... 我不知道如何将链接imageView从的test.xml在我的片段我想要的图像在全屏幕...

Here is my code. 这是我的代码。

Reports.java : Reports.java:

public class Reports extends Fragment {
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (container == null) {
            return null;
        }
        View view = inflater.inflate(R.layout.reports, container, false);
        ButterKnife.inject(this, view);

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

    // Loading image from url in ImageView ... HERE IS THE PROBLEM
    Picasso.with(mImageReport.getContext()).load(mCurrentReportString.getUrlImages()).into(ivPreview);
    mImageReport.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nagDialog.show();
        }
    });

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

                nagDialog.dismiss();
            }
        });


        return view;
    }

test.xml : test.xml:

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

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


    <Button android:layout_width="match_parent"
            android:layout_height="match_parent"   android:background="@drawable/fileclose"
            android:id="@+id/btnIvClose" android:layout_alignParentRight="true"
            android:layout_alignParentTop="true" />
    </RelativeLayout>

Call this method from fragment onCreateView or according to your requirements... 从片段onCreateView或根据您的要求调用此方法...

private void showImage() {
    final Dialog nagDialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    nagDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    nagDialog.setCancelable(false);
    nagDialog.setContentView(R.layout.test);
    Button btnClose = (Button)nagDialog.findViewById(R.id.btnIvClose);
    ImageView ivPreview = (ImageView)nagDialog.findViewById(R.id.iv_preview_image);

    // Loading image from url in ImageView ... HERE IS THE PROBLEM
    Picasso.with(getActivity()).load(mCurrentReportString.getUrlImages()).into(ivPreview);  

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM