Animation的学问


动画播放相信大家一定不会陌生,不过动画的大杀器很多人可能没用过,这里提供三种较为简便的方式开展动画的制作,近期在写的程序总结出来打个点

动画加载的三种方式


第一种

注意AnimationUtils的使用,这里 少了很多麻烦的事情,代码的具体的类需要指定的东西过多,这里写好xml加载进来,让动画尽情的转起来

private void showHead(View head, View content) {
    	head.startAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_top));
    	content.startAnimation(AnimationUtils.loadAnimation(this, R.anim.content_down));
    	content.setPadding(0, 200, 0, 0);
    }
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    >
    <translate
        android:duration="5000"
        android:fromYDelta="-200"
        android:toYDelta="0" />
</set>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    >
    <translate
        android:duration="5000"
        android:fromYDelta="-200"
        android:toYDelta="0" />
</set>


利用系统的AnimationUtils进行动画的播放,这里面可以省掉自己书写很多的参数也算是比较方便


第二种方式:.

int version =  Integer.valueOf(android.os.Build.VERSION.SDK);
			if(version > 5 ){
				overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
			}
注意最关键的这个方法的注释,和两个参数的作用,这个作用很大的,对于outside的Activity也是有作用的
void android.app.Activity.overridePendingTransition(int enterAnim, int exitAnim)


Call immediately after one of the flavors of startActivity(Intent) or finish to specify an explicit transition animation to perform next. 

As of android.os.Build.VERSION_CODES.JELLY_BEAN an alternative to using this with starting activities is to supply the desired animation information through a ActivityOptions bundle to or a related function. This allows you to specify a custom animation even when starting an activity from outside the context of the current top activity.

Parameters:
enterAnim A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
exitAnim A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.


第三种方式

传统的方式  五种动画 直接new出来,然后使用AnimationSet或者单独使用某一个,然后view执行动画


动画的执行方式不止这几种关键是用的好,用的到位才行


第四种

在AndroidManifest里面,对于application和activity标签可以定义theme属性。如果对Application定义了某一个属性,那么会对所有的activity产生影响,当然你可以在activity中覆盖它。

<application android:theme="@style/ThemeActivity">

然后在values/themes.xml中

<style name="ThemeActivity" mce_bogus="1">
<item name="android:windowAnimationStyle">@style/AnimationActivity</item>
<item name="android:windowNoTitle">true</item>
</style>

在values/styles.xml中

<style name="AnimationActivity" parent="@android:style/Animation.Activity" mce_bogus="1">
<item name="android:activityOpenEnterAnimation">@anim/push_left_in</item>
<item name="android:activityOpenExitAnimation">@anim/push_left_out</item>
<item name="android:activityCloseEnterAnimation">@anim/push_right_in</item>
<item name="android:activityCloseExitAnimation">@anim/push_right_out</item>
</style>


这样就可以了,至于anim中的动画,就自己定义啦,这个和普通的animation是一样的,如果不知道的话,请参见

http://developer.android.com/guide/topics/graphics/view-animation.html。

这种方式除了可以定义activity的animation之外,还有task,window出现和结束时候的动画,具体请参见

http://developer.android.com/reference/android/R.styleable.html#WindowAnimation


简单总结,随后会更新

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值