从屏幕底部滑动/拖动 Android 视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21784916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:04:26  来源:igfitidea点击:

Swipe/drag Android view from the bottom of the screen

androidandroid-custom-view

提问by stanete

I want to do in my app a View that I can swipe from the bottom of the window (Images below explain it better).

我想在我的应用程序中做一个视图,我可以从窗口底部滑动(下面的图片更好地解释了它)。

I want the view to stop at certain point. The view must allow to swipe/drag it to the bottom again. Any idea or tip of how can I do that?

我希望视图在某个点停止。视图必须允许再次将其滑动/拖动到底部。关于我该怎么做的任何想法或提示?

This is what I want to have initially

这就是我最初想要的

enter image description here

在此处输入图片说明

采纳答案by Jon

I think you are in search of a ViewDragHelper:

我想你正在寻找一个ViewDragHelper

API doc: https://developer.android.com/reference/android/support/v4/widget/ViewDragHelper.html

API 文档:https: //developer.android.com/reference/android/support/v4/widget/ViewDragHelper.html

How to use. This answer links to a sample project to show you how as well: ViewDragHelper: how to use it?

如何使用。这个答案链接到一个示例项目,向您展示如何使用ViewDragHelper:如何使用它?

Dragging best practices:

拖动最佳实践:

http://developer.android.com/training/gestures/scale.html

http://developer.android.com/training/gestures/scale.html

回答by Nithish V

You can use the new material design pattern called Bottom Sheets. They do the exact thing that you want. They also support custom layouts for the view.

您可以使用称为底部表的新材料设计模式。他们做你想做的事情。它们还支持视图的自定义布局。

Material Design - Component - Bottom Sheets

材料设计 - 组件 - 底板