Android动画——Frame动画
来源:互联网 发布:网络寻衅滋事罪案例 编辑:程序博客网 时间:2024/05/06 12:36
Frame动画即帧动画,与电影放映的原理相同,都是通过帧的快速切换,展现动态的视觉效果。
本文包含帧动画两个方面的应用实例,分别是经典帧动画和旋转帧动画(即转菊花)。
一、经典帧动画实现
第一步:在工程res目录下的drawable目录(没有请自行创建)中新建一个资源文件名为normal.xml:
第二步:编辑资源文件
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" android:visible="false" android:variablePadding="false"> <item android:drawable="@mipmap/a" android:duration="500" /> <item android:drawable="@mipmap/b" android:duration="500" /> <item android:drawable="@mipmap/c" android:duration="500" /> <item android:drawable="@mipmap/d" android:duration="500" /> <item android:drawable="@mipmap/e" android:duration="500" /> <item android:drawable="@mipmap/f" android:duration="500" /></animation-list>
属性介绍:
android:oneshot 如果为true,动画只执行一次android:visible drawable的初始可见行,默认为falseandroid:variablePadding 选择true时,drawable的内边距会根据状态的变化而变化,设置为true时,你必须为不同的状态配置layout,但是通常不建议这么做。选择false时,内边距保持一致,所有状态中最大的内边距。默认为false android:drawable 当前帧引用的drawable资源android:duration 当前帧的显示时间
第三步:使用drawable
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageview" android:layout_width="200dp" android:layout_height="200dp" android:layout_centerInParent="true" android:background="@drawable/normal"/></RelativeLayout>
第四步:启动drawable
1.初始化
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_normal, container, false); imageView = (ImageView) rootView.findViewById(R.id.imageview); animationDrawable = (AnimationDrawable)imageView.getBackground(); return rootView;}
2.启动
public void onResume() { super.onResume(); animationDrawable.start();}
3.停止
public void onResume() { super.onResume(); animationDrawable.start();}
旋转帧动画
第一步:在工程res目录下的drawable目录(没有请自行创建)中新建一个资源文件名为rotate.xml:
第二步:编辑资源文件
<?xml version="1.0" encoding="utf-8"?><animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@mipmap/ic_launcher" android:pivotX="50%" android:pivotY="50%" android:visible="true"/>
属性介绍:
android:drawable 资源文件android:poivotX 旋转中心点的X坐标在drawable的X轴方向的比例android:poivotY 旋转中心店的Y坐标在drawable的Y轴方向的比例android:visible drawable初始可见性
第三步:使用drawable
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/rotate"/></RelativeLayout>
0 0
- Android动画——Frame动画
- Android:动画:Frame动画
- Android开发之动画(Animation)——Frame动画
- Android学习——Frame动画、Shape动画
- Android View动画之——Frame动画
- Android动画——逐帧动画(Frame Animation)
- Android Frame动画——AnimationDrawable
- Android Frame动画——AnimationDrawable
- android动画——Frame by Frame Animation
- 【Android动画】之Frame动画
- 【Android动画】之Frame动画
- 【Android动画】之Frame动画
- 【Android动画】之Frame动画
- 【Android动画】之Frame动画
- Android动画之:Frame动画
- android动画,Tween动画和Frame动画
- android tween、frame动画
- Android --- Frame动画示例
- 图像编码中的小白问题sps ,pps ,nalu ,frame ,silce ect....
- 二维码生成(字符串)
- H264码流结构分析
- 枚举类型Enum用来存放系统常量
- maven pom.xml详解
- Android动画——Frame动画
- 有的食物不能乱吃
- 文字上下滚动的效果
- 【机器学习】ICA 原理以及相关概率论,信息论知识简介
- 查看本机ip
- C++ vector 数组实现
- 老问题新讨论:再论a different object with the same (2010-07-22 01:41:34)
- Linux系统下-进程间通信(消息队列-详解)
- EditText把选项卡顶上去的解决方法