[英]setting layout params after animation
我在這樣的RelativeLayout
有2個視圖:
<?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>
現在,我將view1
的y屬性從0設置為300動畫。但是我希望view2
根據view1
更改其位置-因為view2
設置為低於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
制作新的動畫,所以請不要建議一個。 ;)
有人有建議嗎?
檢查是否可以解決您的問題:
ani.addListener(new AnimatorListenerAdapter()
{
@Override
public void onAnimationEnd(Animator animation)
{
LayoutParams params = view2.getLayoutParams();
// change it ...
params.addRule(RelativeLayout.BELOW, view1.getId());
view2.setLayoutParams(params);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.