我試圖從屏幕底部向上滑動一個視圖到頂部,並且它在做動畫,但最終它會回到屏幕底部。我無法弄清楚爲什麼。繼承人的代碼:Android - 動畫問題
public void slideUp() {
Animation slide = null;
slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, -5.0f);
slide.setDuration(4000);
SubviewManager.getSelectedRouteView().startAnimation(slide);
slide.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
SubviewManager.getSelectedRouteView().clearAnimation();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
SubviewManager.getSelectedRouteView().getWidth(), SubviewManager.getSelectedRouteView().getHeight());
Log.e("Rules", "Rules " + lp.getRules().toString());
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
SubviewManager.getSelectedRouteView().setLayoutParams(lp);
}
});
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/selected_route_layout"
android:padding="10dip"
android:background="#FFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/time_label"
android:textColor="#1D1C18"
android:layout_marginRight="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/eta_label"
android:textColor="#7EC82F"
android:layout_alignBottom="@+id/time_label"
android:layout_toRightOf="@+id/time_label"
android:layout_toEndOf="@+id/time_label" />
<LinearLayout
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/time_label"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/route_breakdown"
android:layout_centerVertical="true"
android:gravity="center_vertical"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/via_label"
android:textColor="#BDBDBD"
android:layout_below="@+id/route_breakdown"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:id="@+id/arrow_up"
android:padding="15dip"
android:src="@drawable/transit_symbol_up_arrow"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</RelativeLayout>
繼承人的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/selected_route_layout"
android:padding="10dip"
android:background="#FFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/time_label"
android:textColor="#1D1C18"
android:layout_marginRight="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/eta_label"
android:textColor="#7EC82F"
android:layout_alignBottom="@+id/time_label"
android:layout_toRightOf="@+id/time_label"
android:layout_toEndOf="@+id/time_label" />
<LinearLayout
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/time_label"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/route_breakdown"
android:layout_centerVertical="true"
android:gravity="center_vertical"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/via_label"
android:textColor="#BDBDBD"
android:layout_below="@+id/route_breakdown"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:id="@+id/arrow_up"
android:padding="15dip"
android:src="@drawable/transit_symbol_up_arrow"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</RelativeLayout>
謝謝你的工作! – Mikerizzo
@Mikerizzo不客氣 –