ViewSwitcher 拖动(参见日历周视图/Google Talk 对话)

发布于 2024-09-12 00:27:53 字数 265 浏览 7 评论 0原文

我想实现类似 Android 日历周视图的功能,您可以在其中浏览周,或者像 Talk 应用程序,您可以在其中切换对话。换句话说,我希望能够拖动视图,而不仅仅是滑动它们。

我似乎唯一能做的就是在滑动操作之后切换视图(使用滑动动画)。在我提到的两个示例中,视图实际上是拖动的,即在屏幕上移动手指时显示动画。

我一直在浏览日历源代码,但是涉及的类太大了,我无法理解它。

有没有人做过这样的事情,或者是否有任何(相对简洁的)资源可用?

干杯。

I want to implement something like the Android Calendar week view, where you can move through the weeks -- or like the Talk app, where you can switch between conversations. In other words, I want to be able to drag the views, not just swipe them.

The only thing that I seem to be able to do is to switch views (with a sliding animation) after the swipe action. In the two examples I mentioned, the views are actually dragged, i.e. the animation shows while moving your finger on the screen.

I've been going through the Calendar source, but the classes involved are so huge, I can't make head nor tail of it.

Has anyone done something like this, or is there any (relatively concise) source available somewhere?

Cheers.

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

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

发布评论

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

评论(2

时光沙漏 2024-09-19 00:27:53

You should be using ViewPager from the android compatibility package.

This is a good place to start. This will do exactly what you want.

鸩远一方 2024-09-19 00:27:53

我查看了日历代码,这就是我的理解:

WeekActivity 包含一个 ViewSwitcher,它由两个 CalendarView 组成。当用户生成滚动事件时,CalendarActivity 会检测到该事件并获取滚动的 X 坐标。当前视图失效,调用CalendarView的onDraw()函数(onDraw()方法是绘制网格和事件的地方)。

onDraw() 中,画布使用 X (canvas.translate(x)) 和另一个的 onDraw() 方法进行平移调用 ViewSwitcher 的视图来填充其余内容。


我希望在我的应用程序中具有相同的行为,但我选择使用图库并对其进行修改以满足我的需要。

I have looked at the calendar code and this is what I understood:

The WeekActivity contains a ViewSwitcher that is composed of two CalendarView. When the user generates a scroll event, the event is detected by the CalendarActivity and get the X coordinate of the scroll. The current view is invalidated, which calls the onDraw() function of the CalendarView (the onDraw() method is where the grid and the events are drawn).

In onDraw(), the canvas is translated using the X (canvas.translate(x)) and the onDraw() method of the other view of the ViewSwitcher is called to fill in the rest of the content.


I wanted to have the same behavior in my app, but I choose to use a Gallery instead and modify it to fit my need.

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