سؤال

How do you setup a ViewSwitcher like the ICS Dialer has? I can setup a ViewSwitcher and make it have a animation when you swipe left or right, but I dont know how to make it so you can actually drag the view left or right!

هل كانت مفيدة؟

المحلول

You can use the Horizontal View Swiping with ViewPager. This is good and recommended way so that your app can run on broader platforms.

نصائح أخرى

You can try this: https://github.com/davidsun/horizontalpager/tree/patch-1.

The basic idea is like this. Firstly, when view is touched, onTouchEvent will be called. But since the view onTouchEvent can be intercepted (by its child view), the parent view must override the onInterceptTouchEvent method. So, just override two methods of ViewGroup, which are onTouchEvent and onInterceptTouchEvent.

Secondly, to build your own displaying method, you need to implement methods onMeasure and onLayout, which calculate the sizes of its child views.

This is the basic idea of building a draggable view switcher.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top