Android动画增加了ImageButton的高度

时间:2016-01-22 23:20:59

标签: android animation android-imagebutton

有人可以让我知道如何设置图像按钮的动画以使高度增加吗? 我读过的任何例子都会缩放按钮的高度。 我只是希望单击时底部的顶部增加高度。我不希望按钮位置移动,只需单击按钮,高度就会增加。 继承我的代码

<ImageButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/buttton"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="66dp"
    android:src="@drawable/iman"
    android:maxHeight="50dp"
    android:minHeight="50dp" />

findViewById(R.id.buttton).setOnClickListener(new  View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Animator scale = ObjectAnimator.ofPropertyValuesHolder(v,
                    PropertyValuesHolder.ofFloat(View.SCALE_Y, 1,             1.5f, 1)
            );
            scale.setDuration(1000);
            scale.start();
        }
    });

由于 克里斯

1 个答案:

答案 0 :(得分:1)

你可以像这样实现你的效果:

final Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(final View v) {
        v.startAnimation(new Animation() {
            private int mStartHeight;
            private int mEndHeight;

            @Override
            public void initialize(final int width, final int height, final int parentWidth, final int parentHeight) {
                mStartHeight = v.getMeasuredHeight();
                mEndHeight = 600;

                setDuration(300);
            }

            @Override
            protected void applyTransformation(final float interpolatedTime, final Transformation t) {
                v.getLayoutParams().height = (int) (mStartHeight + (interpolatedTime * (mEndHeight - mStartHeight)));
                v.requestLayout();
            }
        });
    }
});