Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - ActivityOptionsCompat - Custom Expand Animation

I'm currently trying to figure out how to make a custom expand animation and using ActivityOptionsCompat seems like the best method for this; however, I'm not really sure on how to write a custom transition animation to do the effect I want.

I have a button on top of a list 'Open', which when pressed will shift the ListView below it down, expanding and showing a screen with options. I hope this image explains what I'm trying to accomplish.

Expand Transition Animation

What I'm trying to do is:

  • Set the top "Open" bar to the top bar in the second screen "Title" called "FILTERS"
  • Set a 0px height view that's directly under the "Open" bar to the expanded options list called "FRAME"
  • Set the ViewPager to a 0px height view below the expanded options called "LIST"

But the List doesn't get pushed away, the new screen is just overlayed on top of it.

ViewCompat.setTransitionName( filters, "FILTERS" );
ViewCompat.setTransitionName( frame, "FRAME" );
ViewCompat.setTransitionName( viewPager, "LIST" );

ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
            getActivity(), new Pair<>( filters, "FILTERS" ), new Pair<>( frame, "FRAME" ), new Pair<>( (View)viewPager, "LIST" ) );


ActivityCompat.startActivity( getActivity(), new Intent( getActivity(), Filters.class ),
            options.toBundle() );

Does anyone know how to accomplish this style of transition animation?

Thanks for your time and help.

like image 560
Advice-Dog Avatar asked Nov 23 '15 22:11

Advice-Dog


1 Answers

If it doesn't have to be another activity you can use this nice library here by umano which I used in the past too.

enter image description here

To use it you need to include it in your gradle dependencies :

compile 'com.sothree.slidinguppanel:library:3.2.0'

And then you can use it like this :

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoPanelHeight="68dp"
    sothree:umanoShadowHeight="4dp"
    sothree:umanoParallaxOffset="100dp"
    sothree:umanoDragView="@+id/dragView"
    sothree:umanoOverlay="true"
    sothree:umanoScrollableView="@+id/list">

    <!-- MAIN CONTENT -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.Toolbar
            xmlns:sothree="http://schemas.android.com/apk/res-auto"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/main_toolbar"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            sothree:theme="@style/ActionBar"
            android:layout_width="match_parent"/>
        <TextView
            android:id="@+id/main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="?attr/actionBarSize"
            android:gravity="center"
            android:text="Main Content"
            android:clickable="true"
            android:focusable="false"
            android:focusableInTouchMode="true"
            android:textSize="16sp" />
    </FrameLayout>

    <!-- SLIDING LAYOUT -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:orientation="vertical"
        android:clickable="true"
        android:focusable="false"
        android:id="@+id/dragView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="68dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/name"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:textSize="14sp"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"/>

            <Button
                android:id="@+id/follow"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:textSize="14sp"
                android:gravity="center_vertical|right"
                android:paddingRight="10dp"
                android:paddingLeft="10dp"/>

        </LinearLayout>

        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
        </ListView>
    </LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
like image 125
Niko Adrianus Yuwono Avatar answered Oct 04 '22 13:10

Niko Adrianus Yuwono