ViewFlipper介绍
ViewFilpper类继承于ViewAnimator,而ViewAnimator类继承于FrameLayout。
ViewAnimator:
Base class for a FrameLayout container that will perform执行 animations when switching切换 between its views.
ViewFilpper:
Simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip自动翻转 between each child at a regular interval间隔.
常用API
查看ViewAnimator类的源码可以看出此类的作用主要是为其中的View切换提供动画效果。该类有如下几个和动画相关的方法:
- setInAnimation(Animation)与setInAnimation(Context, resourceID):设置View进入屏幕时候使用的动画
- setOutAnimation、getInAnimation、getOutAnimation:动画
- showNext、showPrevious:显示FrameLayout里面的下/上一个View
- getCurrentView:当前的View。Returns the View corresponding to the currently displayed child.
- setDisplayedChild、getDisplayedChild:正在显示的View的序号。Returns the index of the currently displayed child view.
- setAnimateFirstView(boolean animate)、getAnimateFirstView:True to animate the current View the first time it is displayed, false otherwise.
- 此外还有各种removeView方法。
查看ViewFlipper的源码可以看到,ViewFlipper主要用来实现View的自动切换。该类提供了如下几个主要的方法:
- setFilpInterval:设置View切换的时间间隔,参数为毫秒
- startFlipping:开始进行View的切换,切换会循环进行
- stopFlipping:停止View切换
- isFlipping: 用来判断View切换是否正在进行 。Returns true if the child views are flipping.
- setAutoStart:设置是否自动开始,如果设置为true,当ViewFlipper显示的时候View的切换会自动开始
- isAutoStart:是否为自动开始,Returns true if this view automatically calls startFlipping() when it becomes attached to a window.
一般情况下,我们都会使用ViewFilpper类实现View的切换,而不使用它的父类ViewAnimator类。
案例
public class MainActivity extends Activity );//间隔时间
flipper.setInAnimation(this, animIn);
flipper.setOutAnimation(this, animOut);
flipper.startFlipping();
}
public static class TBean {
public TBean(String title, String pageUrl) {
Title = title;
PageUrl = pageUrl;
}
public String Title;
public String PageUrl;
}
}