ViewSwitcher 拖动(参见日历周视图/Google Talk 对话)
我想实现类似 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 Android 兼容包中的 ViewPager 。
这是一个很好的起点。这将完全符合您的要求。
You should be using ViewPager from the android compatibility package.
This is a good place to start. This will do exactly what you want.
我查看了日历代码,这就是我的理解:
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 aViewSwitcher
that is composed of twoCalendarView
. When the user generates a scroll event, the event is detected by theCalendarActivity
and get the X coordinate of the scroll. The current view is invalidated, which calls theonDraw()
function of the CalendarView (theonDraw()
method is where the grid and the events are drawn).In
onDraw()
, the canvas is translated using the X (canvas.translate(x)
) and theonDraw()
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.