Android的图形与图像处理之三 逐帧动画(Frame)
来源:互联网 发布:淘宝特惠囤 编辑:程序博客网 时间:2024/06/15 18:54
定义逐帧动画非常简单,只要在<animation-list …/>元素中使用<item.../>子元素定义动画的全部帧,并指定各帧的持续时间即可。
android:onshot控制该动画是否循环播放,设为false则会循环播放
也支持在Java代码中创建逐帧动画,调用addFrame(Drawable frame, int duration)向该动画中添加帧
程序获取AnimationDrawable后,接下来就可用ImageView把AnimationDrawable显示出来
示例代码:
res/anim/fat_po.xml
<?xmlversion="1.0"encoding="utf-8"?>
<!-- 指定动画循环播放 -->
<animation-listxmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<!-- 添加多个帧 -->
<itemandroid:drawable="@drawable/fat_po_f01"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f02"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f03"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f04"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f05"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f06"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f07"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f08"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f09"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f10"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f11"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f12"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f13"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f14"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f15"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f16"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f17"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f18"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f19"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f20"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f21"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f22"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f23"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f24"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f25"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f26"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f27"android:duration="60"/>
<!-- 指定动画循环播放 -->
<animation-listxmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<!-- 添加多个帧 -->
<itemandroid:drawable="@drawable/fat_po_f01"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f02"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f03"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f04"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f05"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f06"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f07"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f08"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f09"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f10"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f11"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f12"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f13"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f14"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f15"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f16"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f17"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f18"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f19"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f20"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f21"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f22"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f23"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f24"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f25"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f26"android:duration="60"/>
<itemandroid:drawable="@drawable/fat_po_f27"android:duration="60"/>
</animation-list>
main_activity.xml
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Buttonandroid:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start"
/>
<Buttonandroid:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stop"
/>
</LinearLayout>
<ImageView
android:id="@+id/anim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@anim/fat_po"
android:scaleType="center"
android:layout_gravity="center_horizontal"
/>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Buttonandroid:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start"
/>
<Buttonandroid:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stop"
/>
</LinearLayout>
<ImageView
android:id="@+id/anim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@anim/fat_po"
android:scaleType="center"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
main.java
publicclassMainActivity extends Activity
{
@Override
publicvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取两个按钮
Button play = (Button) findViewById(R.id.play);
Button stop = (Button) findViewById(R.id.stop);
ImageView imageView = (ImageView) findViewById(R.id.anim);
// 获取AnimationDrawable动画对象
finalAnimationDrawable anim = (AnimationDrawable) imageView
.getBackground();
play.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v)
{
// 开始播放动画
anim.start();
}
});
stop.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v)
{
// 停止播放动画
anim.stop();
}
});
}
@Override
publicvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取两个按钮
Button play = (Button) findViewById(R.id.play);
Button stop = (Button) findViewById(R.id.stop);
ImageView imageView = (ImageView) findViewById(R.id.anim);
// 获取AnimationDrawable动画对象
finalAnimationDrawable anim = (AnimationDrawable) imageView
.getBackground();
play.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v)
{
// 开始播放动画
anim.start();
}
});
stop.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v)
{
// 停止播放动画
anim.stop();
}
});
}
}
0 0
- Android的图形与图像处理之三 逐帧动画(Frame)
- Android的图形与图像处理之五 属性动画
- Android图形与图像处理-逐帧动画
- Android的图形与图像处理之四 补间动画(Tween)
- Android的图形与图像处理之六 SurfaceView实现动画
- Android绘图机制与处理技巧(三)——Android图像处理之图形特效处理
- Android图形与图像处理-补间动画
- Android的图形与图像处理之二 图形特效处理
- Android 动画系列之逐帧(Frame)动画详解
- Android动画效果之Frame Animation(逐帧动画)
- Android动画效果之Frame Animation(逐帧动画)
- Android动画效果之Frame Animation(逐帧动画)
- Android动画效果之Frame Animation(逐帧动画)
- Android的图形与图像处理
- Android绘图机制与处理技巧(四)Android图像处理之图形特效处理
- Linux的帧缓冲(Frame Buffer)之二:显示图形和图像
- Linux的帧缓冲(Frame Buffer)之二:显示图形和图像
- Android 学习之逐帧动画(Frame)
- Android的图形与图像处理之一 使用简单图片&绘图
- 蛇形填数(矩阵)
- HDOJ-1787-GCD Again 解题报告
- Android的图形与图像处理之二 图形特效处理
- WebService之WSDL和SOAP实例(基于JAVA)
- Android的图形与图像处理之三 逐帧动画(Frame)
- 读head first servlet and jsp(二)
- webservice:Axis2
- The Blocks Problem
- Android的图形与图像处理之四 补间动画(Tween)
- 使用Jenkins进行持续集成(一)-安装篇
- 工作中常用到的linux命令
- 第八周项目六--本月天数
- 使用Eclipse+Axis2构建Web Service应用(客户端无需生成Stub方式)