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>

参考链接一
参考链接二

更多相关文章

  1. android 三种解析,构建xml方法
  2. Android遍历API (1) 动画篇——克隆动画AnimationCloning
  3. Android 文件管理方法
  4. android中自定义Toast方法详解(一)
  5. android:布局参数,控件属性及各种xml的作用
  6. Android在网络中与JavaWeb的项目进行交互的方法
  7. Android加载Gif图片的一般方法:Movie实现

随机推荐

  1. Android Studio打不开虚拟机,两种情况详解
  2. Android Volley的使用
  3. android隐藏EditText光标
  4. Storm——Android SQLite数据库管理类库
  5. Android MQTT 实现Push
  6. Android(安卓)Studio Gradle Sync同步慢
  7. 《Android学习指南》分享给大家
  8. android:orientation参数说明
  9. Android中使用Gson解析JSON数据,以及把JS
  10. android适配器的使用