这个是用imageview来演示的
//定义一个ViewWrapper
private static class ViewWrapper {
private View mTarget;
public ViewWrapper(View target) {
mTarget = target;
}
public int getWidth() {
return mTarget.getLayoutParams().width;
}
public void setWidth(int width) {
mTarget.getLayoutParams().width = width;
mTarget.requestLayout();
}
}
然后在主方法中就可以使用了
//获取屏幕的宽度
WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
//imageview
imageView = (ImageView) findViewById(R.id.img);
//用ViewWrapper 包住 imageview(也就是需要动画的控件)
ViewWrapper wrapper = new ViewWrapper(imageView);
//属性动画
ObjectAnimator.ofInt(wrapper, "width", width).setDuration(8000).start();