android - 单击图像并使用 Instagram 等操作打开缩放布局
问题描述
我正在尝试像在 Instagram 中那样实现长按图像预览。
我的应用程序有一个包含图像的目录,当我单击任何图像时,它的预览应该出现并在发布后关闭,就像在 Instagram 中一样,同时检查帖子的网格(您可以使用带有评论和心选项的缩放项目布局)。
检查图像 1:这将是列表。
检查图像 2:这就是我在单击列表项时想要的。
我尝试通过使用缩放动画放大视图来实现相同的效果,但它适用于图像而不是整个项目布局。
解决方案
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
推荐阅读
- javascript - 无法从 JavaScript 中的 html 计算器获取按钮
- raku - 是否可以将 TT2 与 Cro 一起使用?
- c# - 如何将全局变量传递给 C# 中的类
- python - 转换ISO时间yyyy-mm-ddThh-mm.ss+hh.mm?
- mysql - Grails - 外部数据库控制器和域
- reactjs - 在 Gatsby 中使用 Helmet 包括外部 javascript
- sql - SQL 语句中的 Databricks 错误:AnalysisException:无法解析 '``' 给定的输入列:
- php - Windows 上的 PhpStorm 设置中缺少 PHPUnit
- python - 用另一个扩展一个列表。为什么会有这种行为?
- python - 在子图中使用现有图