Android动画按钮大小从两侧变化

时间:2017-06-21 18:36:43

标签: android animation button android-animation

Android动画 如何从两侧(左侧和右侧)更改按钮大小 在同一时间 作为这个图像

Image sample

我试过了..但它不像我希望的那样工作

public void scaleView(View v, float startScale, float endScale) {
    Animation anim = new ScaleAnimation(
            startScale, endScale, // Start and end values for the X axis scaling
            1f, 1f, // Start and end values for the Y axis scaling
            Animation.RELATIVE_TO_SELF, 0f, // Pivot point of X scaling
            Animation.RELATIVE_TO_SELF, 1f); // Pivot point of Y scaling
    anim.setFillAfter(true); // Needed to keep the result of the animation
    anim.setDuration(3000);
    v.startAnimation(anim);
}

2 个答案:

答案 0 :(得分:0)

将pivotXValue更改为0.5

public void scaleView(View v, float startScale, float endScale) { Animation anim = new ScaleAnimation( startScale, endScale, // Start and end values for the X axis scaling 1f, 1f, // Start and end values for the Y axis scaling Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling Animation.RELATIVE_TO_SELF, 1f); // Pivot point of Y scaling anim.setFillAfter(true); // Needed to keep the result of the animation anim.setDuration(3000); v.startAnimation(anim); }

答案 1 :(得分:-1)

你试过这个:

v.animate().setDuration(3000).scaleX(endScale);