Animating in RelativeLayout from ScrollView

I am testing a function in which I would like to animate a view from a ScrollView. I think providing a sample layout would be much easier to understand, so here it goes:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@android:color/holo_blue_bright"
        >

        <TextView
            android:id="@+id/tv_label"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="0"
            android:textSize="25sp"
            android:textStyle="bold"/>
    </LinearLayout>

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:background="@android:color/holo_green_light"
        android:padding="5dp"
        >

        <RelativeLayout
            android:id="@+id/lay_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/iv_1"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:background="@android:color/holo_purple"/>

            <ImageView
                android:id="@+id/iv_2"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:layout_below="@+id/iv_1"
                android:layout_marginTop="10dp"
                android:background="@android:color/holo_blue_dark"/>

            <ImageView
                android:id="@+id/iv_3"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:layout_below="@+id/iv_2"
                android:layout_marginTop="10dp"
                android:background="@android:color/holo_green_dark"/>

            <ImageView
                android:id="@+id/iv_4"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:layout_below="@+id/iv_3"
                android:layout_marginTop="10dp"
                android:background="@android:color/holo_red_light"/>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:layout_below="@+id/iv_4"
                android:layout_marginTop="10dp"
                android:background="@android:color/white"/>

            <FrameLayout
                android:id="@+id/bottom_buttons"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <FrameLayout
                    android:id="@+id/frame_cart"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="130dp">

                    <Button
                        android:id="@+id/btn_cart"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end"
                        android:background="@android:color/holo_orange_dark"/>
                </FrameLayout>
            </FrameLayout>

        </RelativeLayout>
    </ScrollView>
</LinearLayout>

      

To summarize: main parent is a LinearLayout containing a title (another LinearLayout) and a ScrollView. In this ScrollView, I have a bunch of Views, and above them there is another View (FrameLayout containing a button in this testing case) that I would like to animate later.

Problem (or at least what I think): For some reason, the RelativeLayout's height is computed as wrapped content and animates that the view at the bottom of the screen doesn't display it as it goes beyond its parent computed height.

In case it will be relevant, this is the running test animation when I click the button:

 AnimatorSet animSet = new AnimatorSet();
        ObjectAnimator animToBottom = ObjectAnimator.ofFloat(frameCart, "translationY", 200);
        animSet.play(animToBottom);
        animSet.setDuration(300);
        animSet.start();

      

+3


source to share





All Articles