Frame动画像gif画画,通过一些静态的图片,以实现动画效果。
Android sdk该AnimationDrawable就是专门针对Frame动画,当然Frame动画也可在java代码或者xml中写,可是提倡大家还是在xml中写,先上个效果图。
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" > <item android:drawable="@drawable/market_loading_01" android:duration="100"/> <item android:drawable="@drawable/market_loading_02" android:duration="100"/> <item android:drawable="@drawable/market_loading_03" android:duration="100"/> <item android:drawable="@drawable/market_loading_04" android:duration="100"/> <item android:drawable="@drawable/market_loading_05" android:duration="100"/> <item android:drawable="@drawable/market_loading_06" android:duration="100"/> <item android:drawable="@drawable/market_loading_07" android:duration="100"/> <item android:drawable="@drawable/market_loading_08" android:duration="100"/> <item android:drawable="@drawable/market_loading_09" android:duration="100"/> <item android:drawable="@drawable/market_loading_10" android:duration="100"/> <item android:drawable="@drawable/market_loading_11" android:duration="100"/> <item android:drawable="@drawable/market_loading_12" android:duration="100"/> </animation-list></span>
Frame动画在xml中的根节点是<animation-list>当中的oneshot=false是循环播放,为true的话则播放到最后一张图片就会停止播放,在java中调用
ImageView imageView; AnimationDrawable animationDrawable; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.image); imageView.setBackgroundResource(R.drawable.drawable_progress); animationDrawable = (AnimationDrawable) imageView.getBackground(); animationDrawable.start();
由于Frame 动画是有一堆静态图构成的所以,能够当成background。
用java代码写的话
AnimationDrawable animationDrawable2 = new AnimationDrawable(); Drawable drawable = getResources().getDrawable(R.drawable.fengjing_1); Drawable drawable2 = getResources().getDrawable(R.drawable.fengjing_2); Drawable drawable3 = getResources().getDrawable(R.drawable.fengjing_3); animationDrawable2.addFrame(drawable, 1000); animationDrawable2.addFrame(drawable2, 1000); animationDrawable2.addFrame(drawable3, 1000); animationDrawable2.setOneShot(false); imageView.setBackgroundDrawable(animationDrawable2); animationDrawable2.start();
恩。。就是这样了,Frame 动画了解到这已经差点儿相同了。
版权声明:本文博客原创文章,博客,未经同意,不得转载。