how to implement umano/AndroidSlidingUpPanel lib

2019-08-11 10:53发布

My App has a map fragment . And on clicking marker , an slide up animation shows from bottom to half of screen . And it slide down on clicking marker again .

I want : Slide up menu should be clickable or drag gable so that it can move to top of screen . to be more clear , i mean either on clicking or dragging this slide up menu which is on half of screen , should go to top of screen .

So far i done : On clicking marker, call the slide up animation to half of screen. : enter image description here

Animation code : slide_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:propertyName="yFraction"
            android:valueType="floatType"
            android:valueFrom="1.0"
            android:valueTo="0.58"
            android:duration="@android:integer/config_mediumAnimTime"/>
    <objectAnimator
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:propertyName="alpha"
            android:valueType="floatType"
            android:valueFrom="0.58"
            android:valueTo="1.0"
            android:duration="@android:integer/config_mediumAnimTime"/>
</set>

slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:propertyName="yFraction"
            android:valueType="floatType"
            android:valueFrom="0.58"
            android:valueTo="1.0"
            android:duration="@android:integer/config_mediumAnimTime"/>
    <objectAnimator
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:propertyName="alpha"
            android:valueType="floatType"
            android:valueFrom="1"
            android:valueTo="0"
            android:duration="@android:integer/config_mediumAnimTime"/>
</set>

The code in Activity which calling this Animation on Marker click :

 public void toggleList() {
        Fragment f = getFragmentManager().findFragmentByTag(LIST_FRAGMENT_TAG);

        if (f != null) {
            getFragmentManager().popBackStack();
        } else {
            getFragmentManager()
                    .beginTransaction()
                    .setCustomAnimations(R.anim.slide_up,
                            R.anim.slide_down,
                            R.anim.slide_up,
                            R.anim.slide_down)
                    .add(R.id.list_fragment_container, BaseMapSlidingFragment
                                    .instantiate(this, BaseMapSlidingFragment.class.getName()),
                            LIST_FRAGMENT_TAG
                    )
                    .addToBackStack(null).commit();
            googleMap.getUiSettings().setAllGesturesEnabled(false);
            if(animCheck == false){
                animCheck = true;
                }else
            {
                    animCheck= false;
            }


        }}

menu_Sliding.up.xml

<?xml version="1.0" encoding="utf-8"?>

<com.trickyandroid.fragmenttranslate.app.view.SlidingRelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="#7c7c7c">

    <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

</com.trickyandroid.fragmenttranslate.app.view.SlidingRelativeLayout>

Custom_View :

  **package com.trickyandroid.fragmenttranslate.app.view;
    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.ViewTreeObserver;
    import android.widget.RelativeLayout;
    /**
     * Created by paveld on 4/13/14.
     */
    public class SlidingRelativeLayout extends RelativeLayout {
        private float yFraction = 0;
        public SlidingRelativeLayout(Context context) {
            super(context);
        }
        public SlidingRelativeLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
        public SlidingRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
        private ViewTreeObserver.OnPreDrawListener preDrawListener = null;
        public void setYFraction(float fraction) {
            this.yFraction = fraction;
            if (getHeight() == 0) {
                if (preDrawListener == null) {
                    preDrawListener = new ViewTreeObserver.OnPreDrawListener() {
                        @Override
                        public boolean onPreDraw() {
                            getViewTreeObserver().removeOnPreDrawListener(preDrawListener);
                            setYFraction(yFraction);
                            return true;
                        }
                    };
                    getViewTreeObserver().addOnPreDrawListener(preDrawListener);
                }
                return;
            }
            float translationY = getHeight() * fraction;
            setTranslationY(translationY);
        }
        public float getYFraction() {
            return this.yFraction;
        }
    }**

Now how to get this menu to top of screen on clicking slide up menu which is on the half of screen ?

1条回答
forever°为你锁心
2楼-- · 2019-08-11 11:25

I suggest you to use AndroidSlidingUpPanel library, that can be found here. There is no point for you to write the same thing again.

It has what you need and much more. It is easy to use and modify (I am using it in my project).

How to use

  • Include com.sothree.slidinguppanel.SlidingUpPanelLayout as the root element in your activity layout.
  • The layout must have gravity set to either top or bottom.
  • Make sure that it has two children. The first child is your main layout. The second child is your layout for the sliding up panel.
  • The main layout should have the width and the height set to match_parent.
  • The sliding layout should have the width set to match_parent and the height set to either match_parent, wrap_content or the max desireable height.
  • By default, the whole panel will act as a drag region and will intercept clicks and drag events. You can restrict the drag area to a specific view by using the setDragView method or umanoDragView attribute.
查看更多
登录 后发表回答