Replicate Google Maps Bottom Panel Swipe Up

后端 未结 1 678
南方客
南方客 2020-12-14 11:24

I\'m trying to replicate Google Maps\' bottom panel swipe up animation:

  1. Tap on Maps marker shows small, portion of bottom panel (header)
  2. Swipe up on t
相关标签:
1条回答
  • 2020-12-14 11:24

    I´ve used this library for that purpouse before and worked pretty good.

    https://github.com/umano/AndroidSlidingUpPanel

    The documentation says this

    This code is heavily based on the opened-sourced SlidingPaneLayout component from the r13 of the Android Support Library. Thanks Android team!

    I´ve tried on Android 2.3.6 and it works perfectly. Don't know if you need it to be backwards compatible but if you do this will be helpful.

    You´ve got the xml part

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Main Content"
            android:textSize="16sp" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center|top"
            android:text="The Awesome Sliding Up Panel"
            android:textSize="16sp" />
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>
    

    And the listeners on your class

    SlidingUpPanelLayout layout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
            layout.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow));
            layout.setAnchorPoint(0.3f);
            layout.setPanelSlideListener(new PanelSlideListener() {
                @Override
                public void onPanelSlide(View panel, float slideOffset) {
                    Log.i(TAG, "onPanelSlide, offset " + slideOffset);
                    if (slideOffset < 0.2) {
                        if (getActionBar().isShowing()) {
                            getActionBar().hide();
                        }
                    } else {
                        if (!getActionBar().isShowing()) {
                            getActionBar().show();
                        }
                    }
                }
    
                @Override
                public void onPanelExpanded(View panel) {
                    Log.i(TAG, "onPanelExpanded");
    
                }
    
                @Override
                public void onPanelCollapsed(View panel) {
                    Log.i(TAG, "onPanelCollapsed");
    
                }
    
                @Override
                public void onPanelAnchored(View panel) {
                    Log.i(TAG, "onPanelAnchored");
    
                }
            });
    

    Also you can state with view will trigger the pane up event.

    Hope it helps! :)

    0 讨论(0)
提交回复
热议问题