三个小李子讲述安卓动画用法
生活随笔
收集整理的這篇文章主要介紹了
三个小李子讲述安卓动画用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這里通過三個小李子來講述一下,Android中通過xml獲取三種動畫的方法。
屬性動畫:從api 11引入
<!--animator/alpha_animator.xml--> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"android:duration="5000"android:propertyName="alpha"android:valueFrom="0.0f"android:valueTo="1.0f"></objectAnimator> ImageView imageView = new ImageView(this);setContentView(imageView);imageView.setImageResource(R.drawable.icon_0);ObjectAnimator objectAnimator = (ObjectAnimator) AnimatorInflater.loadAnimator(this, R.animator.alpha_animator);objectAnimator.setTarget(imageView);objectAnimator.start();視圖動畫:常用alpha/scale/translate/rotate
<!--anim/test.xml--> <set xmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator"><rotate android:duration="1000"android:fromDegrees="0"android:pivotX="50%"android:pivotY="50%"android:startOffset="500"android:toDegrees="360" /><alpha android:duration="500"android:fromAlpha="1.0"android:startOffset="500"android:toAlpha="0.0"></alpha><scale android:duration="500"android:fromXScale="1.0"android:fromYScale="1.0"android:pivotX="50%"android:pivotY="50%"android:startOffset="500"android:toXScale="0"android:toYScale="0"></scale> </set> ImageView imageView = new ImageView(this);setContentView(imageView);imageView.setImageResource(R.drawable.icon_0);Animation animation = AnimationUtils.loadAnimation(this, R.anim.test);imageView.setAnimation(animation);animation.start();幀動畫:幾張圖片的有規律出現
<?xml version="1.0" encoding="utf-8"?> <!--drawable/test.xml--> <animation-list xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/icon_0"android:duration="500"></item><item android:drawable="@drawable/icon_bg_release_topic_a"android:duration="500"></item><item android:drawable="@drawable/icon_1"android:duration="1000"></item></animation-list> ImageView imageView = new ImageView(this);setContentView(imageView);imageView.setBackgroundResource(R.drawable.test);AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();animationDrawable.start();總結
以上是生活随笔為你收集整理的三个小李子讲述安卓动画用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jacket for matlab,Ja
- 下一篇: 开发自己的安卓APP——悬浮备忘录(使用