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

4

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);
}

你尝试过以某种方式去做吗? - gprathour
将您的x轴缩放点从0f更改为0.5f。 - Mohamed Mohaideen AH
2个回答

1
将 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

你试过这个吗:

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

它是不是没有起作用,还是误导了?想知道为什么会被踩! - Shivam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接