如何使用ViewPropertyAnimator将Width设置为特定值 [英] How can one use ViewPropertyAnimator to set Width to a specific value

查看:112
本文介绍了如何使用ViewPropertyAnimator将Width设置为特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ViewPropertyAnimator设置视图宽度?

How can I use ViewPropertyAnimator to set my view width?

我可以缩放或平移(请参见下文),但不能设置为特定的宽度。

I can scale or translate (see below) but I can't set to a specific width.

frame_1.animate().scaleX(5).scaleY(5).start();

但没有

frame_1.animate().width(1024).height(768).start();


推荐答案

使用简单的动画代替ViewPropertyAnimator

Use simple animation instead of ViewPropertyAnimator

public class ResizeWidthAnimation extends Animation
{ 
    private int mWidth;
    private int mStartWidth;
    private View mView;

    public ResizeWidthAnimation(View view, int width)
    { 
        mView = view;
        mWidth = width;
        mStartWidth = view.getWidth();
    } 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t)
    { 
        int newWidth = mStartWidth + (int) ((mWidth - mStartWidth) * interpolatedTime);

        mView.getLayoutParams().width = newWidth;
        mView.requestLayout();
    } 

    @Override 
    public void initialize(int width, int height, int parentWidth, int parentHeight)
    { 
        super.initialize(width, height, parentWidth, parentHeight);
    } 

    @Override 
    public boolean willChangeBounds() 
    { 
            return true; 
    } 
} 

这篇关于如何使用ViewPropertyAnimator将Width设置为特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆