浅谈Android选项卡(四)

来源:互联网 发布:淘宝美工工资待遇 编辑:程序博客网 时间:2024/05/16 05:24

前面几篇介绍的选项的用法,基本上使用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所在的位置。

voidshowNext()

Manually shows the next child.
voidshowPrevious()
Manually shows the previous child.
voidsetDisplayedChild(int whichChild)
Sets which child view will be displayed.
同时使用ViewFlipper还有另外一个好处就是,可以很方便的自定义切换时候的动画。

voidsetInAnimation(Animation inAnimation)

Specifies the animation used to animate a View that enters the screen.
voidsetOutAnimation(Animation outAnimation)
Specifies the animation used to animate a View that exit the screen.
第一个是,当view进来时候的动画,第二是view出去的时候动画,如果动画设置的好,效果也是很不错的,同是如果设置上面的动画,可以设置循环和自动播放所有的页面,类似与Gallery。如果需要了解详细情况,还是需要查看文档。

public class

ViewAnimator

extends FrameLayout
java.lang.Object   ↳android.view.View    ↳android.view.ViewGroup     ↳android.widget.FrameLayout      ↳android.widget.ViewAnimatorKnown Direct Subclasses
Known Indirect Subclasses

ViewAnimator和ViewFlipper、viewSwticher、ImageSwitch、TextSwitcher,基本上功能差不多, 只是适用的对象不一样。

原创粉丝点击