Android set
来源:互联网 发布:java 解压缩tar文件 编辑:程序博客网 时间:2024/06/01 21:42
一、xml文件与java结合
set包含set(对应AnimatorSet).objectAnimator(对应ObjectAnimator).animator(对应ValueAnimator)
<set>
android:ordering=”together|sequentially”//together同时执行,sequentially顺序执行默认together
<objectAnimator
android:propertyName=”string”//指定动画属性的类型如alpha.scaleX等android:valueType=”intType|floatType”//变化值类型,floatType默认
android:valueFrom=”float|int|color”//变化开始值,左负右正
android:valueTo=”float|int|color”//变化结束值,左负右正
android:duration=”int”//动画播放时长,单位毫秒
android:startOffset=”int”//动画延时播放事件
android:repeatCount=”2”//重复次数,-1表示无限重复
android:repeatMode=”reverse|repeat”//前提android:repeatCount=”-1”,reverse反响重复,repeat顺序重复
/>
<animator
...//属性与objectAnimator相同,但一般不用animator
/>
</set>
实例:
myAnimator.xml
<set
android:ordering=”sequentially”
>
<set>
<objectAnimator
android:propertyName=”alpha”
android:duraiton=”500”
android”valueTo=”400”
android:valuteType=”intType”
/>
<objectAnimator
android:propertyName=”scaleX”
android:duration=”500”
android:valueTo=”300”
android:valueTyep=”intType”
/>
</set>
<objectAnimator
android:propertyName=”alpha”
android:duration=”500”
android:valueTo=”1f”
/>
</set>
也可如下
<?xml version=”1.0” encoding=”utf-8”?>
<set>
<alpha
...
/>
<scale
...
/>
...
</set>
详细如下:
1、alpha
<?xml version=”1.0” encoding=”utf-8”?>
<set>
<alpha
xmlns:android=”http://schemas.android.com/apk/res/android”
android:duration=”500”
android:fromAlpha=”1.0”
android:toAlpha=”0.0”
/>
</set>
2、scale
<?xml version=”1.0” encoding=”utf-8”?>
<set>
<scale
xmlns:android=”http://schemas.android.com/apk/res/android”
android:duration=”1000”
android:fromXScale=”0.0”
android:fromYScale=”0.0”
/>
</set>
3、translate
<?xml version=”1.0” encoding=”utf-8”?>
<set>
<translate
xmlns:android=”http://schames.android.com/apk/res/android”
android:duration=”1000”
<!--屏幕左上角为原点,右下角坐标为(320,480)-->
android:fromXDelata=”320”
android:fromYDelate=”480”
android:toXDelta=”0”
android:toYDelta=”0”
/>
</set>
4、rotate
<?xml version=”1.0” encoding=”utf-8”?>
<set>
<rotate
xmlns:android=”http://schames.android.com/apk/res/android”
android:duration=”1000”
android:fromDegerees=”300”
android:toDegress=”-360”
/>
</set>
5、其他
android:fillAfter=”true”//动画结束后保持最后的状态
android:fillBefore=”true”//动画结束后保持开始前的状态
android:interpolator=”@android:anim/decelerate_interpolator”//指定动画插入器,加速减速插入器accelerate_decelerate_interpolator,加速插入器accelerate_interpolator,减速插入器decelerate_interpolator
andorid:repeatCount=”1”//重复次数
android:repeatMode=”reverse”//重复模式
android:startOffSet=”0”//重复时间
android:privotX=”50%”//相对屏幕百分比,50%动画从水平居中位置开始,可设置为数值、百分数、百分数p,比如50、50%、50%p
android:privotY=”50%”//相对屏幕百分比,50%动画从垂直剧中位置开始
Java中解析(方法多样)
AnimatorSet set=(AniamtorSet)AnimatorInflater.loadAnimator(myContext,R.animator.myAnimator);//将动画文件解析为AnimatorSet对象
set.setTarget(myObject);//给指定对象添加动画
set.start();//启动动画
或者
Animation animation=AnimationUtils.loadAnimation(myContext,R.animator.myAnimator);
myObject.startAnimation(animation);
AnimationSet可理解为动画集合,Animation为动画
AnimationSet继承自Animation
duration.repeatMode.fillBefore.fillAfter在AnimationSet中设置有效并作用所有Animaiton
repeatCount.fillEnabled在AnimationSet中设置无效
startOffset.shareInterpolator在AnimationSet中设置有效,但不会作用所有Animation
运用实例:
AnimationSet animation=new AnimationSet(true);
AlphaAniamtion a=new AlphaAnimation(1,0);
RotateAnimation r=new RotateAnimation(0,720,Animation.RELATIVE_TO_SELF,0.5f);
animation.addAnimation(a);
animation.addAniamtion(r);
animation.setDuration(3000);
anim.setStartOffset(1000);
myObject.startAnimation(animation);
二、纯Java文件
1、alpha
//第一个参数view对象,第二个参数动画改变类型,第三个参数开始透明度,第四个参数结束透明度
ObjectAnimator alpha=ObjectAnimator.ofFloat(viewObject,”alpha”,0f,1f);
alpha.setDuration(2000);//设置动画时间
alpha.setInterpolator(new DecelerateInterpolator());//设置动画插入器,减速
alpha.setRepeatCount(-1);//设置动画重复此处,-1为无限循环
alpha.setRepeatMode(Animation.REVERSE);//设置动画循环模式
alpha.start();//启动动画
2、scale
AnimatorSet animatorSet=new AnimatorSet();//组合动画
//第一个参数view对象,第二个参数动画改变类型,第三个参数开始倍数,第四个参数结束倍数
ObjectAnimator scaleX=ObjectAnimator.ofFloat(text,”scaleX”,1f,0f);
ObjectAnimator scaleY=ObjectAnimator.ofFloat(text,”scaleY”,1f,0f);
animatorSet.setDuration(2000);
animatorSet.setInterpolator(new DecelerateInterpolator());
animatorSet.play(scaleX).with(scaleY);//两个动画同时开始
animatorSet.start();
3、translate
ObjectAnimator translationUp=ObjectAnimator.ofFloat(viewObject,”Y”,button.getY(),0);
ttranslationUp.setInterpolator(new DecelerateInterpolator());
translationUp.setDuration(1500);
translationUp.start();
4、rotate
AnimatorSet set=new AnimatorSet();
ObjectAnimator animtor=Objector.ofFloat(viewObject,”rotationX”,0f,180f);
animator.setDuration(2000);
ObjectAnimator animator2=ObjectAnimator.ofFloat(viewObject,”rotationX”,180f,0f);
animator2.setDuartion(2000);
ObjectAnimator animator3=ObjectAnimator.ofFloat(viewObject,”rotationY”,0f,180f);
animator3.setDuration(2000);
ObjectAnimator animator4=ObjectAnimator.ofFloat(viewObject,”rotationY”,180f,0f);
animator4.setDuration(2000);
set.play(animator).before(animator2);//先执行animator动画后执行animator2动画
set.play(animator3).before(animator4);
set.start();//animator与animator3会同时执行
5、
- Android set
- android set custom theme
- Android Attribute Set
- android NetworkTime set
- Android动画----Set
- android Set的遍历
- Android/Java Map/Set/List....
- android xml set,selector,shape
- Android中的Animation <set>使用
- android之set接口用法
- intellij idea set android formatting
- android debug set screen rotation
- Android Paint set方法详解
- Android set Tag, findViewWithTag使用
- Set shadow in Android 5+
- 【Android 4.0】Android Icon Set的使用
- set /?
- Set
- JAVA 串口编程 (一)
- 一个简单首页的布局
- 查找XXXX.class的真实使用路径 (应对那种找不到正确依赖class的问题)
- 鼠标滚轮缩放图纸小工具ZoomIO--通杀Orcad Capture , LayoutPlus , CAM350 , AD , ADPCB , PADS, Foxit Reader
- 【javascript】jQuery中.each循环,如何跳出循环,以及循环数组时对于数组操作时的坑
- Android set
- json
- 玲珑oj 1125 咸鱼商店
- Android layer-list
- 共享内存linux C/C++代码实战------顺便玩下ipcs, ipcrm, shmget, shmat, shmdt, shmctl
- 目录 《虚拟机就是开发板》
- 题目1380:lucky number
- java设计模式---原型模式篇
- Android 资源引用