单击图像时如何在对话框中打开图像?

时间:2019-04-06 17:17:28

标签: java android xml dialog android-imageview

在用户单击图像时我想要的活动中。图像将在对话框中打开。大。

private ImageView mImageView, FailedImg;
        private ProgressBar mProgressBar;

    mImageView = (ImageView) findViewById(R.id.mPinnedPostImg);
            mProgressBar = (ProgressBar) findViewById(R.id.pb);
            FailedImg = (ImageView) findViewById(R.id.ef_failed_image);

            if (TextUtils.isEmpty(list.getmImagePinnedPost())) {
                mImageView.setImageResource(R.drawable.failed_to_load_img);
                mProgressBar.setVisibility(View.GONE);
            } else {

                Picasso.with(getApplicationContext())
                        .load(list.getmImagePinnedPost())
                        .into(mImageView, new Callback() {
                            @Override
                            public void onSuccess() {
                                mProgressBar.setVisibility(View.GONE);
                                FailedImg.setVisibility(View.GONE);
                            }

                            @Override
                            public void onError() {
                                mImageView.setImageResource(R.drawable.app_logo);
                                mProgressBar.setVisibility(View.GONE);
                            }
                        });

1 个答案:

答案 0 :(得分:0)

因此,您可以创建自定义对话框,并在单击图像时将其打开:

  yourImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //in here open your dialog
            yourDialog diag = new yourDialog();
            diag.show();
        }
    });

现在,您可以像这样创建自定义对话框:

public class yourDialog extends Dialog {
Context mContex;

public yourDialog(@NonNull Context context) {
    super(context);
    mContex= context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.invite_dialog);
    closeDialog();
}


private void closeDialog(){
    TextView exit = findViewById(R.id.xButton);
    exit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismiss();//close your dialog
        }
    });
  }
}