animation绘制同心圆
这里是动画相关的详细介绍
http://developer.android.com/intl/zh-cn/guide/topics/resources/animation-resource.html
在实现帧动画的时候有以下几点需要注意:
1) 帧动画不能根据你的view设置的大小进行自动放大缩小
2) 每帧大小需要定义的尺寸一样
实例:
1、 在drawable中实现图片帧(这里实现简单两帧)
frame0.xml中内容如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="oval">
<solid android:color="@android:color/transparent" />
<size android:width="200dp" android:height="200dp"/>
</shape>
</item>
<item android:bottom="56dp"
android:left="56dp"
android:right="56dp"
android:top="56dp">
<shape android:shape="oval">
<solid android:color="#FF16ae2b" />
</shape>
</item>
</layer-list>
frame1.xml中内容如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- inner shadow of outer circle -->
<item>
<shape android:shape="oval">
<solid android:color="@android:color/transparent" />
<size android:width="200dp" android:height="200dp"/>
</shape>
</item>
<item
android:bottom="36dp"
android:left="36dp"
android:right="36dp"
android:top="36dp">
<shape android:shape="oval">
<stroke android:width="2dp" android:color="#cF16ae2b" />
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item
android:bottom="48dp"
android:left="48dp"
android:right="48dp"
android:top="48dp">
<shape android:shape="oval">
<stroke android:width="2dp" android:color="#FF16ae2b" />
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item
android:bottom="56dp"
android:left="56dp"
android:right="56dp"
android:top="56dp">
<shape android:shape="oval">
<solid android:color="#FF16ae2b" />
</shape>
</item>
</layer-list>
2、 在res/anim中实现动画
anim0.xml中内容如下:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/frame0" android:duration="80" />
<item android:drawable="@drawable/frame1" android:duration="80" />
</animation-list>
3、代码实现
private AnimationDrawable showDrawable = null;
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showDrawable
= (AnimationDrawable)context.getResources().getDrawable(R.anim.anim0);
showDrawable.setOneShot(true);
//this.setBackgroundDrawable(showDrawable);将其放到一个view中
}