我试过并试图弄清楚这一点,而我似乎无法使TranslateAnimation正常工作。相反,在屏幕上滑动我的观点,它只是瞬间移动从A点到B点Android TranslateAnimation不起作用
这里是我想在这个例子中要做到:当点击一个按钮,滑动到右侧。
这里发生了什么:它滞后了一会儿,然后只是传送而不是滑动。
这里是我的代码:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button"
android:layout_centerHorizontal="true"
android:layout_below="@+id/anchor"
android:paddingTop="10dp"
android:onClick="AnimateButton"
android:id="@+id/Button"/>
和相应的Java代码:
public void AnimateButton(View view)
{
View playButton = (ImageView) findViewById(R.id.Button);
TranslateAnimation ButtonAnimation = new TranslateAnimation(0, 100, 0, 100);
ButtonAnimation.setDuration(2000);
ButtonAnimation.setFillEnabled(true);
ButtonAnimation.setFillBefore(true);
Button.startAnimation(ButtonAnimation);
}
我曾经尝试这样做,以及fillAfter设置为false,在一个XML创建我自己的动画,其中有同样的故事(传送而不是滑动)。
有人可以帮我解决这个问题。如果有更好的方式来滑动视图,并且我效率低下,请让我知道。谢谢!
P.S.我已经阅读了关于这个主题的其他所有关于stackoverflow的帖子,他们都没有工作到目前为止,但我仍然在搜索,所以请不要只是链接到另一个类似于这个问题的问题。