首页 > 解决方案 > 单击图像并使用 Instagram 等操作打开缩放布局

问题描述

我正在尝试像在 Instagram 中那样实现长按图像预览。

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

检查图像 1:这将是列表。

检查图像 2:这就是我在单击列表项时想要的。

我尝试通过使用缩放动画放大视图来实现相同的效果,但它适用于图像而不是整个项目布局。

标签: androidandroid-imageviewandroid-cardviewzooming

解决方案


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


推荐阅读