[英]How can I move View from Y position to another Y
我有一个按钮,我想按下按钮 animation。 我做到了,但是功能留在了以前的位置(就像按钮移动但是如果我点击它,它不起作用,但是如果我点击它之前的 position 它会起作用)
Animation logbtn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.logbtnanim);
button.startAnimation(logbtn);
animation 代码是这样的。
PS Parent 是约束布局。
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromYDelta="0"
android:toYDelta="100"
android:duration="1000"/>
</set>
首先,如果你只有一个 animation,你不需要 AnimatorSet 标签。如果你想一起播放多个动画,可以使用它。
其次,您使用的是TranslateAnimation ,它不会为 Buttons 属性设置动画,它只会移动屏幕上的像素,因此在 animation 之后,Android 仍然认为视图位于旧的 position,这就是为什么它仍然可以在那里单击的原因。
我建议使用ViewPropertyAnimator在 Java 代码中执行此操作,例如:
button.animate().translationY(...f).duration(1000);
或ObjectAnimator ,它更灵活一些,因为您也可以在 xml 中执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.