我想Views
在我的布局中显示 3 个,但一次只能显示 2 个。当我按下一个按钮时,我希望最左边的视图向左滑出,中间的视图随之滑动,占据左视图的起始空间,最右边的视图应该滑入屏幕。
以下是一些截图:
动画前:
在动画期间(绘画编辑^^):
动画后:
这是我的布局文件:
<?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>
所以我可以使用下面的代码将最左边的视图动画到屏幕外:
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);
}
});
这会将最左边的视图设置为左侧窗口的动画,并将其设置为消失。我也可以将中间视图动画到新位置,但是当动画完成时,中间视图会在很短的时间内跳回其原始位置,之后它会占据正确的位置。我怎样才能避免这种跳跃?