gpt4 book ai didi

android - 转换 View 后,您按下以触发按钮按下的区域不会移动。你如何用 View 移动这个区域?

转载 作者:行者123 更新时间:2023-11-29 17:15:49 25 4
gpt4 key购买 nike

我创建了一个按钮,并希望它在触发某些事件后移动到屏幕底部。所以我制作了一个 TranslateAnimation 对象

    private TranslateAnimation setupAnimation(float yOffset) {
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, yOffset);
animation.setDuration(1000);
animation.setFillAfter(true);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
return animation;
}

然后我将 TranslateAnimation 对象传递到我想要移动的 View 的 startAnimation() 方法中。

好吧,这适用于我想在视觉上完成的事情,但我注意到我无法点击可见的地方,但我可以按下按钮原来所在的位置,然后将执行 onClick 回调。

翻译后,我需要做什么才能让用户在新位置按下按钮?

最佳答案

TranslateAnimation 仅移动屏幕上的像素,它不会改变 Button 的实际位置,它只是看起来像在移动,因此您的 OnClick/OnTouchListener 不会随它一起设置动画。

使用 ObjectAnimator 或 ViewPropertyAnimator 真正改变 Button 的属性。

这是一个使用 ViewPropertyAnimator 的例子让你开始:

yourButton.animate()
.translationY(yOffset)
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(1000);

检查Docs对于其他可用的方法。

关于android - 转换 View 后,您按下以触发按钮按下的区域不会移动。你如何用 View 移动这个区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39064706/

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