Android学习——Frame动画、Shape动画
来源:互联网 发布:js中控制div隐藏 编辑:程序博客网 时间:2024/05/27 14:15
1. Frame帧动画
animation-list
属性oneshot : 帧动画的自动执行。如果为true,表示动画只播放一次停止在最后一帧上,如果设置为false表示动画循环播放。
示例:
新建/drawable/anim_img.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/img01" android:duration="1000"/> <item android:drawable="@drawable/img02" android:duration="1000"/> <item android:drawable="@drawable/img03" android:duration="1000"/> <item android:drawable="@drawable/img04" android:duration="2000"/> <item android:drawable="@drawable/img05" android:duration="2000"/> <item android:drawable="@drawable/img06" android:duration="1000"/> <item android:drawable="@drawable/img07" android:duration="1000"/> <item android:drawable="@drawable/img08" android:duration="1000"/></animation-list>
布局文件:
<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" tools:context="${relativePackage}.${activityClass}" > <ImageView android:id="@+id/imgv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:text="frame动画测试" /></RelativeLayout>
java文件:
public class MainActivity extends Activity { private ImageView imgv; private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imgv = (ImageView) this.findViewById(R.id.imgv); btn = (Button) this.findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { imgv.setBackgroundResource(R.drawable.anim_img); AnimationDrawable animationDrawable = (AnimationDrawable) imgv.getBackground(); animationDrawable.start(); } }); }}
运行效果:
2. shape动画
背景选择器:
gradient渐变
stroke描边
conners圆角
新建背景选择器res/layout/btn_selector.xml:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <!-- 渐变 --> <gradient android:endColor="#FFFFFF" android:startColor="#ff0000" android:type="linear" android:gradientRadius="20"/> <!-- 描边 --> <stroke android:width="8dp" android:color="#00ff00" android:dashWidth="10dp" android:dashGap="5dp"/> <!-- 圆角 --> <corners android:radius="10dp"/> <padding android:left="10dp" android:top="5dp" android:right="10dp" android:bottom="5dp"/> </shape> </item> <item > <shape> <!-- 渐变 --> <gradient android:endColor="#ff0000" android:startColor="#ff0000"/> <!-- 描边 --> <stroke android:color="#000000"/> <padding android:left="10dp" android:top="5dp" android:right="10dp" android:bottom="5dp"/> </shape> </item></selector>
布局文件中添加一个Button按钮:
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@layout/btn_selector" android:text="shape测试" />
运行效果:
点击按钮之后:
0 0
- Android学习——Frame动画、Shape动画
- Android动画——Frame动画
- Android:动画:Frame动画
- Android开发之动画(Animation)——Frame动画
- 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学习篇章17-动画1Frame动画AnimationDrawable
- druid.io sql支持
- Linux2.6.32驱动笔记(3)分析应用程序read访问驱动过程
- 关于阅读那些大神的开源库的一些感想
- UI树
- python面向对象
- Android学习——Frame动画、Shape动画
- 微信支付之认识微信支付开发
- C#方便操作数据总结
- SQL Server中的三种物理连接图文解析:Loop Join,Merge Join,Hash Join
- const在函数前与函数后的区别
- LeetCode Longest Valid Parentheses
- Java 里把 InputStream 转换成 String 的几种方法
- UVa 10074 - Take the Land
- 转载】Maven + SVN + Hudson 自动编译、部署、发布