标签:-- xmlns ansi 对比 bsp .com 添加 指定 渐变
1.alpha改变view的透明度的动画
2.基本属性:
duration="5000" 渐变时间
fromAlpha="1" 起始时的透明度 1为不透明
toAlpha="0" 结束时透明度 0为透明
3.java
AlphaAnimation anim=new AlphaAnimation(1, 0); anim.setDuration(5000); v.startAnimation(anim);
4.xml
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" android:fromAlpha="1" android:toAlpha="0" > </alpha>
5.xml 启动
Animation anim = AnimationUtils.loadAnimation(this,R.anim.alpha_first); v.startAnimation(anim);
6.Activity 转场动画 /anim
alpha_in
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromAlpha="0" android:toAlpha="1" > </alpha>
alpha_out
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromAlpha="1" android:toAlpha="0" > </alpha>
java:
Intent it=new Intent(this,Alpha2Activity.class); startActivity(it); overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
1.旋转动画
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" android:fromDegrees="1" android:pivotX="50%" android:pivotY="50%" android:toDegrees="180" > </rotate>
android:pivotX="50%"
android:pivotY="50%" 旋转中心点 view的中信
android:fromDegrees="1"起始时view的角度
android:toDegrees="180" 旋转结束后的角度
选择角度为正时是顺时针旋转,为负时则是逆时针旋转。
2.java:
RotateAnimation anim=new RotateAnimation(0, 90); anim.setDuration(5000); v.startAnimation(anim);
3.xml
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotate_frist); v.startAnimation(anim);
1.缩放动画
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" android:fromXScale="1" android:fromYScale="1" android:repeatCount="infinite" android:repeatMode="reverse" android:toXScale="3" android:toYScale="1" > </scale>
2.java
//缩放动画 x--1变成0.3 y变成2 放大一倍 ScaleAnimation anim=new ScaleAnimation(1, 0.3f, 1, 2); //时长 anim.setDuration(5000); v.startAnimation(anim);
1.位置移动
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" android:fromXDelta="1" android:fromYDelta="1" android:interpolator="@android:anim/bounce_interpolator" android:toXDelta="1" android:fillAfter="true" android:toYDelta="300" > </translate>
android:interpolator="@android:anim/bounce_interpolator" // 动画执行速率
android:fillAfter="true" 动画结束时,停留在最后位置
2.转场动画
translate_in
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromXDelta="1" android:fromYDelta="-100%" android:toXDelta="1" android:toYDelta="0" > </translate>
translate_out
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromXDelta="1" android:fromYDelta="1" android:toXDelta="1" android:toYDelta="100%" > </translate>
Intent it=new Intent(this,Alpha2Activity.class); startActivity(it); overridePendingTransition(R.anim.translate_in, R.anim.translate_out);
3.java
/* * 300:x方向移动的距离 */ TranslateAnimation anim=new TranslateAnimation(1, 300, 1, 1); anim.setDuration(5000); v.startAnimation(anim);
4.xml
//加载xml Animation anim = AnimationUtils.loadAnimation(this, R.anim.translate_first); v.startAnimation(anim);
1.java
AlphaAnimation a=new AlphaAnimation(1, 0); RotateAnimation b=new RotateAnimation(0, -180); //动画集:旋转的同时淡出 AnimationSet set=new AnimationSet(true); set.addAnimation(a); set.addAnimation(b); set.setDuration(5000); v.startAnimation(set);
2.xml
Animation anim = AnimationUtils.loadAnimation(this, R.anim.set_first); v.startAnimation(anim);
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" > <scale android:fromXScale="1" android:fromYScale="1" android:toXScale="0" android:toYScale="0" > </scale> <translate android:fromXDelta="1" android:fromYDelta="1" android:toXDelta="200" android:toYDelta="300" > </translate> </set>
3.activity转场
set_in
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" > <scale android:fromXScale="0" android:fromYScale="0" android:pivotX="50%" android:pivotY="50%" android:toXScale="1" android:toYScale="1" /> <alpha android:fromAlpha="0" android:toAlpha="1" /> </set>
set_out
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" > <!-- 缩小淡出 --> <scale android:fromXScale="1" android:fromYScale="1" android:pivotX="50%" android:pivotY="50%" android:toXScale="0" android:toYScale="0" /> <alpha android:fromAlpha="1" android:toAlpha="0" /> </set>
Intent it=new Intent(this,Alpha2Activity.class); startActivity(it); overridePendingTransition(R.anim.set_in, R.anim.set_out);
由多张图片循环播放形成的动画
1.drawable/文件 多张图片
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/loading_0" android:duration="100"/> <item android:drawable="@drawable/loading_1" android:duration="100"/> <item android:drawable="@drawable/loading_2" android:duration="100"/> <item android:drawable="@drawable/loading_3" android:duration="100"/> <item android:drawable="@drawable/loading_4" android:duration="100"/> <item android:drawable="@drawable/loading_5" android:duration="100"/> <item android:drawable="@drawable/loading_6" android:duration="100"/> <item android:drawable="@drawable/loading_7" android:duration="100"/> </animation-list>
2.image中利用
<ImageView android:id="@+id/imageView1" android:layout_width="67dp" android:layout_height="54dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@drawable/frame_first" />
3.java
ImageView mv=(ImageView) findViewById(R.id.imageView1); AnimationDrawable drawable = (AnimationDrawable) mv.getBackground(); drawable.start();
1.补间动画(view动画)的变换只是假象,view的属性值没有发生任何变化,是android操作系统
通过重新绘制实现的
属性动画:
通过改变属性值完成的动画
2.translated对比
TranslateAnimation a=new TranslateAnimation(1, 300, 1, 1); a.setDuration(3000); a.setFillAfter(true); v.startAnimation(a);
ObjectAnimator.ofFloat(v, "TranslationY",200).setDuration(2000).start();
在X,Y方向移动,移动后translate无法点击,属性动画依然可以相应点击事件
3.监听
ObjectAnimator anim = ObjectAnimator.ofFloat(v, View.ROTATION_Y, 0,90,180); anim.setDuration(5000); anim.start(); //添加监听器 anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); } }); }
4.动画集
AnimatorSet s=new AnimatorSet(); ObjectAnimator a = ObjectAnimator.ofFloat(v, View.ALPHA, 1,0); ObjectAnimator b = ObjectAnimator.ofFloat(v, View.ROTATION, 1,-90,180,360); s.setDuration(5000); s.playTogether(a,b); s.start();
5.xml animator/文件
Animator anim = AnimatorInflater.loadAnimator(this,R.animator.property_first); //指定动画作用的对象 anim.setTarget(v); //启动 anim.start();
6.java
/* * v:动画作用的view对象 * View.TRANSLATION_X:被改变值的属性 * 第三个参数:属性取值的范围 */ ObjectAnimator anim = ObjectAnimator.ofFloat(v, View.TRANSLATION_X,1,20,1,-20,1); anim.setDuration(300); anim.start();
http://pan.baidu.com/s/1mioO8ju
标签:-- xmlns ansi 对比 bsp .com 添加 指定 渐变
原文地址:http://www.cnblogs.com/galibujianbusana/p/7122938.html