Reputation: 233
I have a relative layout (let's call it A), inside a scroll view, inside a relative layout (we will call this layout B)
What I'm trying to do is remove a child from A, insert it into B and align it to the parent top (right below the action bar).
I've been trying to animate this slide up, and back down to it's original position without any luck.
Any idea how can I perform this animation?
Upvotes: 0
Views: 3049
Reputation: 10095
A very late reply, but here's how I managed this:
center_to_top_center.xml (located in res/anim/)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fillAfter="true"
android:fromXDelta="0%p"
android:fromYDelta="00%p"
android:toXDelta="00%p"
android:toYDelta="-40%p" />
</set>
HomeActivity.java
public class HomeActivity extends FragmentActivity {
@InjectView(R.id.imageView2)
ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_home, false);
beginLogoAnimation();
}
private void beginLogoAnimation(){
Animation translateAnim= AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.center_to_top_center);
translateAnim.setFillAfter(true);
translateAnim.setFillEnabled(true);
translateAnim.setFillBefore(false);
translateAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mImageView.startAnimation(translateAnim);
}
}
activity_home.xml
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:layout_centerInParent="true"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:src="@drawable/logo"
/>
Upvotes: 1
Reputation: 5297
Since you are Animating Layout Changes
Try adding this to your layout block:
android:animateLayoutChanges="true"
Source: http://developer.android.com/guide/topics/graphics/prop-animation.html#layout
Upvotes: 0