一般不直接使用ViewAnimator而是使用它的两个子类ViewFlipper和ViewSwitcher。

- ViewSwitcher allows only two views, while ViewFlipper allows more. ViewSwitcher is Useful if you have 2 Views that you have to go back and forth fairly regularly. if you want features like the ViewFactory and you only got 2 views use the ViewSwitcher. ViewSwitcher is used in circumstances where the view is the same but the data is different – like on a calendar app – we’re just changing the data in the view.
- ViewFlipper can be used if you want to periodically change the views. Say like an automated flipping book of some sort. Though a custom-adapter gallery is much better at this.
- with ViewPager, each “page” is itself a Fragment.
- onDoubleTap(MotionEvent e):通知DoubleTap手势,
- onDoubleTapEvent(MotionEvent e):通知DoubleTap手势中的事件,包含down、up和move事件(这里指的是在双击之间发生的事件,例如在同一个地方双击会产生DoubleTap手势,而在DoubleTap手势里面还会发生down和up事件,这两个事件由该函数通知);
- onSingleTapConfirmed(MotionEvent e):用来判定该次点击是SingleTap而不是DoubleTap,如果连续点击两次就是DoubleTap手势,如果只点击一次,OPhone系统等待一段时间后没有收到第二次点击则判定该次点击为SingleTap而不是DoubleTap,然后触发SingleTapConfirmed事件。
- onDown(MotionEvent e):down事件;
- onSingleTapUp(MotionEvent e):一次点击up事件;
- onShowPress(MotionEvent e):down事件发生而move或则up还没发生前触发该事件;
- onLongPress(MotionEvent e):长按事件;
- onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY):滑动手势事件;
- onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY):在屏幕上拖动事件。
ViewFlow=ViewFlipper + ScrollView
首先在你的layout文件中加入:
<org.taptwo.android.widget.ViewFlow
android:id=”@+id/viewflow”
app:sidebuffer=”5″/>
其中app:sidebuffer属性是ViewFlow组件自定义的,使用这些属性时,需要增加如下的xml的命名空间:
xmlns:app=”http://schemas.android.com/apk/res/your.application.package.here”
然后在你的Activity里面添加如下代码用于使用ViewFlow:
ViewFlow viewFlow = (ViewFlow) findViewById(R.id.viewflow);
viewFlow.setAdapter(myAdapter);//or 设置初始view的位置 viewFlow.setAdapter(myAdapter, 8);
//监听view切换事件,简单的需求可不监听
viewFlow.setOnViewSwitchListener(new ViewSwitchListener()
{ public void onSwitched(View v, int position) { / / Your code here 16 17 } });
- 圆点指示器还支持activeColor、inactiveColor、activeType(填充或描边)、inactiveType(填充或描边)、fadeOut(设置圆点自动隐藏的秒数,若为0则不会自动隐藏)、radius(圆点的半径)等。