android 动画学习之ViewFlipper

来源:互联网 发布:上海淘宝职位招聘网 编辑:程序博客网 时间:2024/04/28 05:41
androd主页面的动画效果。ViewFlipper实现起来很简单
1.定义一个xml文件
<Linearlayout android:layout_height="fill_parent"android:layout_width="fill_parent" android:orientation="vertical"xmlns:android="http://schemas.android.com/apk/res/android">
   <Viewflipperandroid:id="@+id/flipper"
       android:layout_height="fill_parent"
       android:layout_width="fill_parent">

       <include android:id="@+id/firstlayout"layout="@layout/first"></include>
       <include android:id="@+id/secondlayout"layout="@layout/second"></include>
       <include android:id="@+id/thirdlayout"layout="@layout/third"></include>
       <include android:id="@+id/fourthlayout"layout="@layout/fourth"></include>
   
   </Viewflipper>
</Linearlayout>
2.ViewFlipper在同一个页面就显示其中一个layout。ViewFlipper中的四个layout很简单,我们就放置一张图片,如下所示:

<Linearlayoutandroid:gravity="center_vertical"

   android:layout_height="fill_parent"  

   android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
   <imageviewandroid:layout_height="wrap_content"

          android:layout_width="wrap_content"  

          android:src="@drawable/v1">
</imageview>

</Linearlayout>

3.      mFlipper = (ViewFlipper) findViewById(R.id.flipper);

        1>显示前一个后一个动画并设置进出动画方式
        mFlipper.setInAnimation(inFromLeftAnimation());
        mFlipper.setOutAnimation(outToRightAnimation());
        mFlipper.showPrevious();
        
        mFlipper.setInAnimation(inFromRightAnimation());
        mFlipper.setOutAnimation(outToLeftAnimation());
        mFlipper.showNext();

       2>开始停止动画

       mViewFlipper.stopFlipping();

       mViewFlipper.startFlipping();


0 0
原创粉丝点击