学习使我快乐使我开心
安卓的动画大体分为三部分 请看图:
由上图可以知道安卓中动画主要分为这三大类 分别为视图动画(View Animation) ,帧动画(Drawable Animation),属性动画(PropertyAnimation)
根据上图我们就可以知道这章我要讲什么了 哈哈 那就是帧动画
柿子要挑软的捏 难题嘛我们就先从简单的着手
帧动画:图片按照顺序一帧一帧组合而成的动画
废话不多说直接看代码:
文件存放路径: main/res/drawable
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<!--android:oneshot="false" ,true表示只播放一次,false则相反-->
<item
android:drawable="@drawable/first"
android:duration="500"/>
<item
android:drawable="@drawable/second"
android:duration="500"/>
<item
android:drawable="@drawable/third"
android:duration="500"/>
<item
android:drawable="@drawable/fourth"
android:duration="500"/>
</animation-list>
第一种方法
布局中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imgview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
activity中:
imageView = findViewById(R.id.imgview);
AnimationDrawable animationDrawable = (AnimationDrawable) getResources().getDrawable(R.drawable.zhendonghua);
imageView.setImageDrawable(animationDrawable);
animationDrawable.start();//开启动画
animationDrawable.stop();//关闭动画
第二种
布局中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imgview"
android:background="@drawable/zhendonghua"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
activity中:
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
//判断是否在运行
if(!animationDrawable.isRunning()){
//开启帧动画
animationDrawable.start();
}
好啦 关于帧布局就到这里了 因为帧布局很简单所以就不更多的演示了 我会在后面更新中将安卓的动画慢慢学习更新玩的
喜欢的话请给我来个小赞吧 你的支持是我最大的动力!!!