属性动画完成控件拉宽

来源:互联网 发布:星目读屏软件 编辑:程序博客网 时间:2024/06/05 08:54

这个是用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();