Android属性动画(ObjectAnimation)
来源:互联网 发布:中国大数据产业联盟 编辑:程序博客网 时间:2024/04/29 08:13
public void objectAnimation(View v){ LinearLayout llProgress = (LinearLayout) findViewById(R.id.ll_progress); final float scale = getResources().getDisplayMetrics().density; float distance = (255 * scale + 0.5f); ViewWrapper wrapper = new ViewWrapper(llProgress); ObjectAnimator animator = ObjectAnimator.ofInt(wrapper,"width",(int)distance); animator.setDuration(4000); animator.start(); }
public void ivAnimation(final View v){ //单个属性 ObjectAnimator.ofFloat(v,"rotationX",0f,180f).setDuration(1000).start(); ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(v, "yjs", 1f, 0f); objectAnimator.setDuration(1000); objectAnimator.start(); //多个属性动画方法一 objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float scale = animation.getAnimatedFraction(); v.setAlpha(scale); v.setScaleX(scale); v.setScaleY(scale); } }); //多个属性动画方法二 PropertyValuesHolder phx = PropertyValuesHolder.ofFloat("alpha",1f,0f); PropertyValuesHolder phy = PropertyValuesHolder.ofFloat("scaleX",1f,0f); PropertyValuesHolder phz = PropertyValuesHolder.ofFloat("scaleY",1f,0f); ObjectAnimator.ofPropertyValuesHolder(v,phx,phy,phz).setDuration(3000).start(); //动画定义在xml文件中 Animator animator = AnimatorInflater.loadAnimator(this,R.animator.scale); animator.setTarget(v); animator.start(); }
//如果某个属性没有get和set方法需要写一个wrapper类将get set封装 private class ViewWrapper{ private View target; public ViewWrapper(View v){ target= v; } public int getWidth(){ return target.getLayoutParams().width; } public void setWidth(int width){ target.getLayoutParams().width = width; target.requestLayout(); } }
xml文件
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="together"> <objectAnimator android:duration="1000" android:propertyName="scaleX" android:valueFrom="1.0" android:valueTo="2.0" android:valueType="floatType" > </objectAnimator> <objectAnimator android:duration="1000" android:propertyName="scaleY" android:valueFrom="1.0" android:valueTo="2.0" android:valueType="floatType"></objectAnimator></set>
参考链接一
参考链接二
0 0
- Android属性动画(ObjectAnimation)
- ObjectAnimation动画属性
- 帧动画(FrameAnimation) 补间动画(TweeAnimation) 属性动画(ObjectAnimation)
- ObjectAnimation动画 + ValueAnimation动画监听
- ObjectAnimation 浅谈(一)
- ObjectAnimation
- Android动画之属性动画(二)
- Android动画(3)--属性动画
- Android Property动画(属性动画)
- Android动画--属性动画总结(一)
- Android 动画(二) 属性动画
- Android动画之属性动画(上)
- Android动画之属性动画(下)
- Android动画机制-属性动画(一)
- Android动画机制-属性动画(二)
- Android动画详解(三) 属性动画
- Android动画案例(三)属性动画
- Android中的动画(三)属性动画
- 20160216.CCPP体系详解(0026天)
- Unity中,利用shader将NGUI图集大小缩小四倍
- Android支持的媒体格式
- Android可动态改变compoundDrawable颜色的TextView
- java加密(对称)
- Android属性动画(ObjectAnimation)
- qgis cad
- UILabel 整理
- _attribute_((packed))
- 概率统计:第六章 样本及抽样分布
- 20160209.CCPP体系详解(0019天)
- jquery防止重复提交表单
- 通过类比在VS2010中调用Matlab dll文件,实现在Qt Creator中调用Matlab Dll文件
- Python自动生成sql语句