我该如何完全按照Material Design文档中所示的那样执行滑动删除手势?

问题描述 投票:-1回答:1

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

java android material-design swipe
1个回答
0
投票

从外观上,您可以使用其他活动来显示信息。要执行过渡动画的起点,您可以执行类似的操作以获取坐标。

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

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

上面的代码将为您提供视图在窗口中的位置,包括左,上,右,下坐标。

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

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);

这将执行您在该链接上看到的动画。 (如果有更简单的方法,那么我不知道它是什么。)

© www.soinside.com 2019 - 2024. All rights reserved.