安卓控件属性动画使用大全
来源:互联网 发布:unity3d 技能释放 编辑:程序博客网 时间:2024/06/07 06:20
首先写一个xml布局文件,用于显示效果,如下
按照把动画都写在xml中比较清晰可靠,下面的例子全是依据xml的写法
2、旋转
3、大小变化
4、平移
6、帧动画,注意帧动画要用到imgView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.dialogtest.AnimationActivity" > <Button android:id="@+id/alpha" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="透明度按钮" /> <Button android:id="@+id/rotate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="旋转按钮" /> <Button android:id="@+id/translate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="平移按钮" /> <Button android:id="@+id/scale" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="大小按钮" /> <Button android:id="@+id/set" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="多重动画按钮" /> <Button android:id="@+id/prop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="属性动画按钮" /> <ImageView android:id="@+id/imgList" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/animation_list" /></LinearLayout>
然后在Activity中抓取所有的按钮
Button alphaButton = (Button) findViewById(R.id.alpha);Button rotateButton = (Button) findViewById(R.id.rotate);Button transButton = (Button) findViewById(R.id.translate);Button scaleButton = (Button) findViewById(R.id.scale);Button setButton =(Button) findViewById(R.id.set);Button propButton = (Button) findViewById(R.id.prop);
1、透明度动画
在Activity中写法1:
直接通过对象进行设置
Animation alpha = new AlphaAnimation(0,1);alpha.setDuration(5000);alphaButton.setAnimation(alpha);写法2:
通过xml文件设置
Animation alpha2 = AnimationUtils.loadAnimation(this,R.anim.animation_alpha);alphaButton.setAnimation(alpha2);
按照把动画都写在xml中比较清晰可靠,下面的例子全是依据xml的写法
//旋转动画Animation rotate = AnimationUtils.loadAnimation(this, R.anim.animation_rotate);rotateButton.setAnimation(rotate);//平移动画Animation translate = AnimationUtils.loadAnimation(this, R.anim.animation_translate);transButton.setAnimation(translate);//大小动画Animation scale = AnimationUtils.loadAnimation(this, R.anim.animation_scale);scaleButton.setAnimation(scale);//多重动画Animation set = AnimationUtils.loadAnimation(this, R.anim.animation_set);setButton.setAnimation(set);//逐帧动画ImageView imgList = (ImageView) findViewById(R.id.imgList);AnimationDrawable animationDrawable = (AnimationDrawable) imgList.getDrawable();animationDrawable.start();//属性动画ObjectAnimator oa=ObjectAnimator.ofFloat(propButton, "rotationX", 0.0f, 360f);oa.setDuration(5000);oa.start();
下面是xml文件的写法
1、透明度渐变
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0" android:toAlpha="1" android:duration="5000"> </alpha>
2、旋转
<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="720" android:duration="5000"> </rotate>
3、大小变化
<?xml version="1.0" encoding="utf-8"?><scale xmlns:android="http://schemas.android.com/apk/res/android" android:fromXScale="0" android:toXScale="200" android:fromYScale="0" android:toYScale="200" android:duration="5000" > </scale>
4、平移
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0" android:toXDelta="500" android:duration="5000"> </translate>
如果想要加入插补效果,比如平移到头超出一块,再弹回来,可以这样写
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0" android:toXDelta="500" android:duration="5000" android:interpolator="@android:anim/overshoot_interpolator"> </translate>
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000"> <alpha android:fromAlpha="0" android:toAlpha="1"></alpha> <translate android:fromXDelta="0" android:toXDelta="200"></translate> </set>
6、帧动画,注意帧动画要用到imgView
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/btn_qq_nor" android:duration="150"></item> <item android:drawable="@drawable/btn_qq_press" android:duration="150"></item> <item android:drawable="@drawable/btn_sina_nor" android:duration="150"></item> <item android:drawable="@drawable/btn_sina_press" android:duration="150"></item> <item android:drawable="@drawable/btn_weichat_nor" android:duration="150"></item> <item android:drawable="@drawable/btn_weichat_press" android:duration="150"></item> <item android:drawable="@drawable/btn_tenteweibo_nor" android:duration="150"></item> <item android:drawable="@drawable/btn_tenteweibo_press" android:duration="150"></item></animation-list>
0 0
- 安卓控件属性动画使用大全
- 安卓笔记:安卓控件属性大全
- 安卓属性动画
- 安卓-属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓属性动画
- 安卓 属性动画
- 安卓控件大全
- 安卓控件属性
- 安卓控件属性
- spark操作hbase中的数据
- (小笔记)Activity中的edittext不能自动弹出软件盘- 的解决
- 团队开发共用一个开发者账号
- 我奋斗了十八年才和你坐在一起喝咖啡
- andorid之摄像头驱动流程
- 安卓控件属性动画使用大全
- 中科院开源协会镜像站 Android SDK镜像测试发布
- Java线程(篇外篇):阻塞队列BlockingQueue
- mysql性能优化-慢查询分析、优化索引和配置
- delphi正则表达式学习笔记(二)
- UE3 体积感光束教程
- js日期格式化(javascript Date format)
- txt文件导入到 SQL SERVER (指定列)
- Oracle 11g安装到85%的时候就停止不动了