如何制作一个在滑动/滑动时在视图之间翻转的 Android 视图

发布于 2024-12-14 01:57:42 字数 539 浏览 2 评论 0原文

我想在我的 Android 应用程序中创建一个可以通过滑动/滑动在多个视图之间切换的视图。我希望它的行为或多或少类似于 Android 启动器在视图之间切换时的行为。特别是,

  1. 它应该在滑动时翻转视图。
  2. 一般来说,滑动会在一个视图和下一个视图之间翻转。它不应该跨越所有的观点。
  3. 如果您缓慢滑动,您应该会看到视图在滑动时拖动,例如。启动器的方式。

我尝试按照 Romain Guy 的 博客使用带有 GestureOverlayView 的 ViewFlipper在此处发布,但用户滑动时没有任何指示。这使得可发现性变得困难,这大概就是 Launcher 这样做的原因。

我尝试使用 Gallery 对象,但是当我从左向右滑动时,有一定的动量使用户浏览所有视图,而不仅仅是将他们带到下一个视图。

有没有好的方法来完成我想做的事情?

I'd like to make a view in my Android app that flips between multiple views on a swipe/fling. I'd like it to behave more or less like the Android Launcher behaves when flipping between views. In particular,

  1. It should flip views on swipe.
  2. Generally a swipe will flip between one view and the next. It should not fling across all of the views.
  3. If you swipe slowly, you should see the views dragging as you're swiping, eg. the way the Launcher does it.

I tried using a ViewFlipper with a GestureOverlayView as per Romain Guy's blog post here, but there's no indicator to the user as they're swiping. This makes discoverability difficult, which is presumably why Launcher does it the way they do.

I tried using a Gallery object, but when I swipe from left to right, there's a certain amount of momentum that flings the users through all the views rather than just taking them to the next view.

Is there a good way to accomplish what I'm trying to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

嘿咻 2024-12-21 01:57:42

我知道这是一个老问题,但 ViewPager 是为了同样的目的而创建的。 ViewPager 是 Android 兼容性包的一部分,更多内容可以在 http:// /android-developers.blogspot.com/2011/08/horizo​​ntal-view-swiping-with-viewpager.html

I know this is an old question but ViewPager is created for this exact same purpose. ViewPager is part of android compatibility package and more can be found at http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html

追我者格杀勿论 2024-12-21 01:57:42

看看 Horizo​​ntalPager。它实际上基于 RealViewSwitcher,其中turn 基于 Android 主屏幕的代码,支持带拖动反馈的对齐分页以及嵌套的垂直滚动子视图。对快速滑动的手势支持并不是应有的全部,但这可能会帮助您实现这一目标(并且我欢迎您回来贡献)。

编辑:从 2012 年开始,使用 Google 的 ViewPager 会更好 - 它位于 compat 库中。

Take a look at HorizontalPager. It's actually based on RealViewSwitcher, which in turn is based on the Android homescreen's code, and supports snap-to paging with drag feedback, as well as nested vertically-scrolling subviews. Gesture support for fast swipes isn't all it should be, but this may get you part of the way there (and I'd welcome contributions back).

EDIT: As of 2012 you're much better off using Google's ViewPager - it's in the compat library.

千と千尋 2024-12-21 01:57:42

查看此项目中的 SwipeView https://github.com/fry15/uk.co .jasonfry.android.tools 它完全按照您想要的方式执行,并且实现起来非常简单。

Check out SwipeView within this project https://github.com/fry15/uk.co.jasonfry.android.tools It does exactly what you want it to do and is super simple to implement.

烟若柳尘 2024-12-21 01:57:42

@CommonsGuy 扩展了 ViewFlipper 来做到这一点。
https://github.com/commonsguy/cwac-viewswiper
我还没有使用过这个,所以我不确定它是否像启动器一样随着你的手指移动,如果不是,你将不得不制作一个 OnTochListener 来为你做这件事。ACTION_MOVE 你将更新视图以更改其位置。如果您没有得到其他答案,我回家后会发布一些示例代码。

@CommonsGuy extended ViewFlipper to do it.
https://github.com/commonsguy/cwac-viewswiper
Ihaven't used this one yet so im not sure if it moves with your finger like the launcher if not your going to have to make an OnTochListener to do it for you in me.ACTION_MOVE you will update the view to change its position. I'll post some sample code when I get home if you don't get another answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文