I want to show 3 Views
in my layout, but only 2 at a time. When I press a button, I want the most left view to slide out to the left, the middle one to slide with it, taking the start space of the left view, and the most right view should slide into the screen.
Here are some screenshots:
Before animation:
During animation (paint edit ^^):
After animation:
This is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3" >
<FrameLayout
android:id="@+id/stations_stations"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:background="@drawable/fragment_border" />
<FrameLayout
android:id="@+id/stations_singlestation"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="2"
android:background="@drawable/fragment_border" />
<FrameLayout
android:id="@+id/stations_trip"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:background="@drawable/fragment_border"
android:visibility="gone" />
</LinearLayout>
So I am able to animate the lefmost view out of the screen using the code below:
final View stationsContainer = findViewById(R.id.stations_stations);
Animation an = AnimationUtils.loadAnimation(this, R.anim.slide_out_left);
stationsContainer.startAnimation(an);
an.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
stationsContainer.setVisibility(View.GONE);
}
});
This animates the leftmost view out of the window to the left, and sets it to gone. I can also animate the middle view to the new location, but when the animation is done, the middle view jumps back to its original position for a very short time, after which it takes the correct position. How can I avoid this jumping?