首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

用ViewFlipper兑现各种切换动画

2012-09-12 
用ViewFlipper实现各种切换动画?1、main.xml?ViewFlipper android:id@+id/flipper?? ? ? ?android:layo

用ViewFlipper实现各种切换动画

?

1、main.xml

?

<ViewFlipper android:id="@+id/flipper"

?? ? ? ?android:layout_width="match_parent"

?? ? ? ?android:layout_height="wrap_content"

?? ? ? ?android:flipInterval="2000"

?? ? ? ? >

?? ? ? ? ? ? ? ?<TextView

?? ? ? ? ? ? ? ? ? ? ? ?android:layout_width="match_parent"

?? ? ? ? ? ? ? ? ? ? ? ?android:layout_height="wrap_content"

?? ? ? ? ? ? ? ? ? ? ? ?android:gravity="center_horizontal"

?? ? ? ? ? ? ? ? ? ? ? ?android:textSize="26sp"

?? ? ? ? ? ? ? ? ? ? ? ?android:text="aaaaaaaaa"/>

?? ? ? ? ? ? ? ?<TextView

?? ? ? ? ? ? ? ? ? ? ? ?android:layout_width="match_parent"

?? ? ? ? ? ? ? ? ? ? ? ?android:layout_height="wrap_content"

?? ? ? ? ? ? ? ? ? ? ? ?android:gravity="center_horizontal"

?? ? ? ? ? ? ? ? ? ? ? ?android:textSize="26sp"

?? ? ? ? ? ? ? ? ? ? ? ?android:text="bbbbbbbb"/>

?? ? ? ? ? ? ? ?<TextView

?? ? ? ? ? ? ? ? ? ? ? ?android:layout_width="match_parent"

?? ? ? ? ? ? ? ? ? ? ? ?android:layout_height="wrap_content"

?? ? ? ? ? ? ? ? ? ? ? ?android:gravity="center_horizontal"

?? ? ? ? ? ? ? ? ? ? ? ?android:textSize="26sp"

?? ? ? ? ? ? ? ? ? ? ? ?android:text="ccccccccc"/>

?? ? ? ? ? ? ? ?<TextView

?? ? ? ? ? ? ? ? ? ? ? ?android:layout_width="match_parent"

?? ? ? ? ? ? ? ? ? ? ? ?android:layout_height="wrap_content"

?? ? ? ? ? ? ? ? ? ? ? ?android:gravity="center_horizontal"

?? ? ? ? ? ? ? ? ? ? ? ?android:textSize="26sp"

?? ? ? ? ? ? ? ? ? ? ? ?android:text="dddddddddd"/>

?? ?</ViewFlipper>

?

2、代码:

?

?

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

//以下是各种动画设置

?

?

//向上消失

mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_up_in));

mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_up_out));

?

//旋转消失

mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.hyperspace_in));

mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.hyperspace_out));

?

mFlipper.startFlipping();//动画循环切换各个子控件

?

3、动画

push_up_in.xml

?

<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="300"/>

<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />

</set>

?

push_up_out.xml

?

<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="300"/>

<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />

</set>

?

hyperspace_in.xml

?

<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" android:startOffset="1200" />


hyperspace_out.xml

?

<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">

<scale?

android:interpolator="@android:anim/accelerate_decelerate_interpolator"

android:fromXScale="1.0"?

android:toXScale="1.4"?

android:fromYScale="1.0"?

android:toYScale="0.6"?

android:pivotX="50%"

android:pivotY="50%"

android:fillAfter="false"

android:duration="700" />

<set?

android:interpolator="@android:anim/accelerate_interpolator"

?? ? ? ? ? ? ? ?android:startOffset="700">

<scale

android:fromXScale="1.4"?

android:toXScale="0.0"

? ? ? ?android:fromYScale="0.6"

android:toYScale="0.0"?

android:pivotX="50%"?

android:pivotY="50%"?

android:duration="400" />?

<rotate?

android:fromDegrees="0"?

android:toDegrees="-45"

android:toYScale="0.0"?

android:pivotX="50%"?

android:pivotY="50%"

android:duration="400" />

</set>

</set>


热点排行