2015-06-08 56 views
0

我试过并试图弄清楚这一点,而我似乎无法使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的帖子,他们都没有工作到目前为止,但我仍然在搜索,所以请不要只是链接到另一个类似于这个问题的问题。

回答

0

其实我只是想通了。由于某种原因,它在我的手机上不起作用,但我在另一部手机上试过了,它工作得很好。我正在运行4.4.4,另一部手机是4.3(三星和Verizon,虽然我不知道这有多大的影响,但我知道他们调整了一些操作系统,所以我想我把它扔到那里)。我的手机是银河注4边缘,它的工作原理是银河注3(再一次,可能没有什么区别,但我想我可以通过它)。

我要报告这个问题,希望能尽快解决。