Android Animations do not affect layout
Animations affect only the drawing of widgets, which means after the animation is done, my FrameLayout screenMain is still at its previous location, y need set the FrameLayout in the next location.
screenMain.setOnClickListener(new View.OnClickListener() {
int i = 0;
@Override
public void onClick(View view) {
if (i % 2 == 0) {
screenMain.startAnimation(translate);
sh.startAnimation(translate);
sg.startAnimation(translate);
i++;
} else {
screenMain.startAnimation(translateb);
sh.startAnimation(translateb);
sg.startAnimation(translateb);
i++;
}
}
});
Code animation
<?xml version="1.0" encoding="utf-8"?>
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0.0"
android:toXDelta="0.0"
android:fromYDelta="0.0"
an开发者_如何学Pythondroid:toYDelta="180.0"
android:duration="200"
android:fillAfter="true"
android:fillEnabled="true"
/>
</set>
Code animationb
<?xml version="1.0" encoding="utf-8"?>
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0.0"
android:toXDelta="0.0"
android:fromYDelta="180.0"
android:toYDelta="0.0"
android:duration="200"
android:fillAfter="true"
android:fillEnabled="true" />
</set>
To change a view's position, you need to call view.setLayoutParams(). An easy way to achieve this animation effect is to first call setLayoutParams() to the end position, then invoke TranslateAnimation from the original location.
Here's more details of how to: http://www.clingmarks.com/?p=400
精彩评论