gpt4 book ai didi

Android动画增加ImageButton的高度

转载 作者:行者123 更新时间:2023-11-30 01:37:25 25 4
gpt4 key购买 nike

有人可以告诉我如何为图像按钮设置动画以增加高度吗?我读过的任何示例都会缩放按钮的高度。我只希望底部的顶部在单击时增加高度。我不希望按钮位置移动,只需单击按钮,高度就会增加。这是我的代码

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

谢谢克里斯

最佳答案

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

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

关于Android动画增加ImageButton的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34957583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com