前面几篇介绍的选项的用法,基本上使用TabActivity、ViewPager、已经基本上满足开发需求了。但是这里再介绍一种小技巧,在有的时候,感觉使用前面的ViewPager和Fragment时候,感觉有点大材小用的感觉。
http://blog.csdn.net/xia215266092/article/details/9613897
http://blog.csdn.net/xia215266092/article/details/9613985
http://blog.csdn.net/xia215266092/article/details/9616075
比如下面这种情况,在微博的界面中有个选项卡,全部、我收听的、认证用户,如果使用ViewPager+Fragment,是肯定可以实现的。但是今天我介绍使用ViewFlipper,可以查看api文档,ViewFlipper里面可以有很多类容,但是每次只能显示一个view,这样就基本上满足图片中标签的来回切换功能了。
布局的结构可以如下。
<ViewFlipper>
<ListView/>
<ListView/>
<ListView/>
</ViewFlipper>
下面是切换的页面的方法,shownext和shorpervious,分别是显示上一个和下一个,setDisplayedChild是具体显示某一个子view,传递的参数就是ziview所在的位置。
|
Manually shows the next child.
|
|
Manually shows the previous child.
|
|
Sets which child view will be displayed.
|
|
Specifies the animation used to animate a View that enters the screen.
|
|
Specifies the animation used to animate a View that exit the screen.
|
java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.widget.FrameLayout | |||
↳ | android.widget.ViewAnimator |
Known Direct Subclasses |
Known Indirect Subclasses |
ViewAnimator和ViewFlipper、viewSwticher、ImageSwitch、TextSwitcher,基本上功能差不多, 只是适用的对象不一样。