0
我有一個RelativeLayout
這樣2次:設置佈局PARAMS
<?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" >
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/shape_red"/>
<View
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/view1"
android:background="@drawable/shape_blue"/>
</RelativeLayout>
現在
,i從0的view1
y屬性動畫〜300,但我想view2
改變根據view1
其位置 - 因爲view2
設置爲低於(layout-below)view1
。
因爲這不起作用,我試圖添加一個onAnimationEnd
聽衆的動畫。像這樣:
ObjectAnimator ani = ObjectAnimator.ofFloat(view1, "Y", 200);
ani.setDuration(2000);
ani.addListener(new AnimatorListenerAdapter()
{
@Override
public void onAnimationEnd(Animator animation)
{
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, view2.getHeight());
params.addRule(RelativeLayout.BELOW, view1.getId());
view2.setLayoutParams(params);
}
});
但view2
根本沒有改變它的位置。
如果可能的話,我想避免爲view2
製作一個新的動畫,所以請不要爲此建議一個。 ;)
有沒有人有一些建議?
可悲的是沒有。它沒有。仍然像以前一樣。 view2不會從最初的位置移動。 – marcin 2012-07-18 12:42:26