单击图像并使用Instagram等操作打开缩放布局

时间:2018-05-03 07:39:36

标签: android android-imageview android-cardview zooming

我试图在Instagram中实现长按图像预览。

我的应用程序有一个目录,其中包含图像,当我点击任何图像时,其预览应该在Instagram中发布之后出现并关闭,同时检查网格的帖子(您可以使用带注释和心脏选项的缩放项目布局)

检查Image 1:这将是列表。

检查Image 2:这就是我想要点击列表项目。

我尝试通过Enlarge a view using a zoom animation实现相同的目标,但它适用于Image而不是整个项目布局。

1 个答案:

答案 0 :(得分:1)

public void show(Context context, ImageView source) {
        BitmapDrawable background = ImagePreviewerUtils.getBlurredScreenDrawable(context, source.getRootView());

        View dialogView = LayoutInflater.from(context).inflate(R.layout.view_image_previewer, null);
        ImageView imageView = (ImageView) dialogView.findViewById(R.id.previewer_image);

        Drawable copy = source.getDrawable().getConstantState().newDrawable();
        imageView.setImageDrawable(copy);

        final Dialog dialog = new Dialog(context, R.style.ImagePreviewerTheme);
        dialog.getWindow().setBackgroundDrawable(background);
        dialog.setContentView(dialogView);//You can set your custem view here
        dialog.show();

        source.setOnTouchListener(new View.OnTouchListener() {
            @Override public boolean onTouch(View v, MotionEvent event) {
                if (dialog.isShowing()) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    int action = event.getActionMasked();
                    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
                        v.getParent().requestDisallowInterceptTouchEvent(false);
                        dialog.dismiss();
                        return true;
                    }
                }
                return false;
            }
        });
    }
  

注意:根据需要修改对话框内容视图(布局)

将此缩放布局与透明对话框主题Zoom Layout

一起使用