易网时代-编程资源站
Welcome
微信登录
编程资源
图片资源库
蚂蚁家优选
PDF转换器
软件资源
软件开发
、
小程序制作
、
系统集成与运维
、
空间租用
、
硬件开发
、
视频监控
、
技术咨询与支持
——联系电话:0311-88999002/88999003
首页
/
操作系统
/
Linux
/
Android游戏开发之使用AnimationDrable实现Frame动画
Android开发中在制作2D帧动画中提供了使用XML配置动画文件的方式绘制,也就是说Android底层提供了动画播放的接口,那么我们分析一下如何调用它的接口来绘制动画。首先在工程res资源文件夹下创建anim动画文件夹,在这个文件夹中建立一个animation.xml文件, 这样它的路径就为re/anim/animation.xml。
看看内容应该是很好理解的,<animation-list>为动画的总标签,这里面放着帧动画 <item>标签,也就是说若干<item>标签的帧 组合在一起就是帧动画了。<animation-list > 标签中android:oneshot="false" 这是一个非常重要的属性,默认为false 表示 动画循环播放, 如果这里写true 则表示动画只播发一次。 <item>标签中记录着每一帧的信息android:drawable="@drawable/a"表示这一帧用的图片为"a",下面以此类推。 android:duration="100" 表示这一帧持续100毫秒,可以根据这个值来调节动画播放的速度。
<animation-list
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:oneshot
=
"false"
>
<item
android:drawable
=
"@drawable/a"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/b"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/c"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/d"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/e"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/f"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/g"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/h"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/i"
android:duration
=
"100"
/>
<item
android:drawable
=
"@drawable/j"
android:duration
=
"100"
/>
</animation-list>
下面这个例子的内容为 播放动画 与关闭动画 、设置播放类型 单次还是循环、拖动进度条修改动画的透明度,废话不多说直接进正题~~
<?xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:orientation
=
"vertical"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
>
<LinearLayout
android:orientation
=
"horizontal"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
>
<Button
android:id
=
"@+id/button0"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"播放动画"
/>
<Button
android:id
=
"@+id/button1"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"停止动画"
/>
</LinearLayout>
<RadioGroup
android:id
=
"@+id/radiogroup"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:orientation
=
"horizontal"
>
<RadioButton
android:id
=
"@+id/checkbox0"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:checked
=
"true"
android:text
=
"单次播放"
/>
<RadioButton
android:id
=
"@+id/checkbox1"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"循环播放"
/>
</RadioGroup>
<TextView
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"拖动进度条修改透明度(0 - 255)之间"
/>
<SeekBar
android:id
=
"@+id/seekBar"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:max
=
"256"
android:progress
=
"256"
/>
<ImageView
android:id
=
"@+id/imageView"
android:background
=
"@anim/animation"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
/>
</LinearLayout>
收藏该网址
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图