Android帧动画实现
来源:互联网 发布:阿里巴巴商机助理 mac 编辑:程序博客网 时间:2024/05/29 09:01
文章主要介绍了安卓帧动画的实现过程。
下面是java代码,其实很简单,关键的地方就四行:
public class MainActivity extends Activity { private ImageView refreshView; private AnimationDrawable animationDrawable; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); refreshView = (ImageView) findViewById(R.id.refreshView); refreshView.setImageResource(R.drawable.refresh_animation); animationDrawable = (AnimationDrawable) refreshView.getDrawable(); animationDrawable.start(); }}以下是布局文件的代码:
<RelativeLayout xmlns: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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="80dp" android:id="@+id/refresh"> <RelativeLayout android:layout_marginLeft="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/refreshView" android:src="@drawable/f1" android:layout_marginLeft="50dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout android:orientation="vertical" android:layout_toRightOf="@id/refreshView" android:layout_marginTop="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/refreshTextOne" android:text="正在刷新数据..." android:textColor="@color/material_blue_grey_950" android:textSize="15sp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/refreshTextTwo" android:text="松手更新" android:textColor="#50000000" android:layout_marginTop="4dp" android:textSize="12sp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </RelativeLayout> </RelativeLayout></RelativeLayout>
实现这一过程最重要的一步就是在drawable下新建refresh_animation.xml文件,代码如下:
<?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/f1" android:duration="150"></item> <item android:drawable="@drawable/f2" android:duration="150"></item> <item android:drawable="@drawable/f3" android:duration="150"></item> <item android:drawable="@drawable/f4" android:duration="150"></item> <item android:drawable="@drawable/f5" android:duration="150"></item> <item android:drawable="@drawable/f6" android:duration="150"></item> <item android:drawable="@drawable/f7" android:duration="150"></item> <item android:drawable="@drawable/f8" android:duration="150"></item></animation-list>
duration可以设置图片更换的时间长短。
大家可以试试,只是实现以下效果,最终效果没有问题。
另注,这里有一篇很好的关于安卓动画的文章值得学习入门:http://www.2cto.com/kf/201410/342375.html
0 0
- Android帧动画实现
- Android实现帧动画
- Android动画解析2-帧动画实现
- Android动画之帧动画实现方式
- android之帧动画实现
- Android 帧动画的实现
- Android--xml实现帧动画
- Android中帧动画实现
- Android帧动画的实现
- Android帧动画的实现
- android帧动画实现方式
- Android中的动画实现详解(2)--逐帧动画
- Android逐帧动画、属性动画的简单实现
- Android逐帧动画、属性动画的简单实现
- Android动画之animation-list实现逐帧动画
- Android动画-帧动画
- Android动画--帧动画
- Android学习笔记--实现帧动画
- Android:EditText专题
- 线程的创建方式选择哪个更好呢?
- 面试题:6个问题
- hdu1542 Atlantis(扫描线+线段树+离散)矩形相交面积
- linux(三)
- Android帧动画实现
- 阿里巴巴笔试题集锦
- php 读取某目录下的所有文件
- 《项目管理修炼之道》阅读笔记(1)
- ant实现批量打包android应用
- python dir __dict__
- [leetcode] 241.Different Ways to Add Parentheses
- MCS 简单博弈
- 九度oj 1075