繁体   English   中英

如何实现滑动删除手势,完全如 Material Design 的文档中所示?

[英]How can I implement swipe-to-delete gesture, exactly as shown in Material Design's documentation?

我想为我的 ListView 实现滑动删除手势,Material Design 文档显示它可以完成(见这里)。 有没有一种简单的方法可以做到这一点,或者我是否打算实现一个自定义 class 扩展ItemTouchHelper.SimpleCallback以添加此行为?

从外观上看,您可以使用另一个活动来显示信息。 要执行 animation 关于它应该从哪里开始的过渡,您可以执行类似的操作来获取坐标。

从列表视图(这是在适配器中调用的子视图,我的意思是containerView

Rect rect = new Rect();
child.getGlobalVisibleRect(rect);

上面的代码将为您提供 window 中视图的 position,具有左、上、右、下坐标。

打开活动时,您可以像这样创建意图:

Intent intent = new Intent(context, DetailsActivity.class);

// This is the "rect" you got above, the view's coordinates in screen.
intent.setSourceBounds(rect);

// Pass necessary elements through Intent.putExtra()
// These will contain the product's information.
// DO NOT PASS IMAGES HERE, ONLY PASS IMAGE REFERENCES.
intent.putExtra("name", product.name);

// Then start the activity normally.
context.startActivity(intent);

这应该执行您在该链接上看到的 animation。 (如果有更简单的方法,顺便说一句,我不知道它是什么。)

暂无
暂无

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

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