j'ai 2 vues dans un RelativeLayout
comme celui-ci:mise en page de réglage params après l'animation
<?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>
maintenant, j'animez la propriété y de view1
de 0 à 300. mais je veux view2
changer sa position selon view1
- parce que view2
est configuré pour être ci-dessous (layout-below) view1
. Comme cela ne fonctionne pas, j'ai essayé d'ajouter un écouteur onAnimationEnd
à l'animation. comme ceci:
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);
}
});
mais view2
n'a pas changé sa position du tout.
Je voudrais éviter de faire une nouvelle animation pour view2
si possible, alors s'il vous plaît ne vous embêtez pas à en suggérer un. ;)
Quelqu'un at-il des suggestions?
malheureusement pas. ce n'est pas le cas. toujours comme avant. view2 ne bouge pas de sa place initiale. – marcin