我写了一个简单的动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate android:fromXDelta="0" android:toXDelta="-320"
android:fromYDelta="0" android:toYDelta="0"
android:duration="5000"/>
</set>
在antivity里的button使用了这个动画后,由于android:fillAfter="true",故动画结束时button停在了动画最后一祯的位置,但是发现button的onClick还是在动画第一祯的位置,也就是最初的位置可以触发onClick。
而我原来的解决办法是,将android:fillAfter="false",然后在动画结束时button.layout(l,t,r,b)来设置位置,但是这样View会闪一下,效果很不好,大家有什么好的方法吗?谢谢!
------解决方案--------------------
试下这个效果, 之前view会闪一下我也是被郁闷了很久...
TranslateAnimation animationOpen = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
animationOpen.setDuration(500);
------解决方案--------------------
动画开始的时候你把button的visiable设置为gone, 然后设置layout位置, 在设置visiable,同时在这里开启上面的动画。。。
------解决方案--------------------
好办法帮顶了