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