Search code examples
androidscaleandroid-relativelayout

how to fit RelativeLayout after a Scale Animation


After apply this animation to my (chield)RelativeLayout, my backgroud image has the good size but my Layout seem to continue to take to much place on my Page (parent)RelativeLayout. Some idea?

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:toXScale="0.2"
    android:toYScale="0.2"
    android:duration="700"
    >
</scale>
</set>

<RelativeLayout ...>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/chieldLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/bigImage"
    >
    <Button
        style="@style/boutonBrun"
        android:id="@+id/btPanier"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/full22lightgreen"

        />

</RelativeLayout>

</RelativeLayout>

I have add like you propose me a listener to fit my layout with this command :

params.width = (int)  getResources().getDimension(R.dimen.size_width);

how can I know the "size_width" that I have to put? Like I ask to scale from 1.0 to 0.2 and finaly put android:layout_width="300dp", I have imagine that "size_width" have to take 60dp (300 * 0.2) but it's very to small compare to size after the animation.


Solution

  • Use animation listener like this

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
    
            }
    
            @Override
            public void onAnimationEnd(Animation animation) {
                // set height for your relative layout here
            }
    
            @Override
            public void onAnimationRepeat(Animation animation) {
    
            }
        });