andeey
andeey

Reputation: 63

Umano AndroidSlidingUpPanel dragging panel with height = 0

I have a problem with the Umano AndroidSlidingUpPanel that I do not seem to find a solution to. I want two views, one on top the other with the option to scroll up and down just like in the demo at https://github.com/umano/AndroidSlidingUpPanel which works flawlessly. However, I want the top view to be completely hidden while collapsed, as if sothree:umanoPanelHeight="0dp". The problem with this line that I can not reach the panel when the height is 0. Google Maps has the functionality I want, when you slide the menu in from the left side and slide it back in from the right.

My code is pretty much similar to the one in the demo, so I see no point in pasting any code here. I am open to other options to solving this, but I need backwards compatibility to early Android versions.

Thanks for any input on this!

Upvotes: 1

Views: 1113

Answers (1)

Stigasaur
Stigasaur

Reputation: 86

I wanted a similar function: I wanted to keep the panel height at 0 and expand on swipe.

  1. Make a custom layout and override the onTouchIntercepted method
  2. Add logic to call and set a callback event from the activity (use an interface)
  3. In your Activity, find the custom view by ID and set a new callback, in the callback set your panel state to PanelState.EXPANDED

Here's and example class I got from the Github page by a Contributor:

public class SlidingAwareLinearLayout extends LinearLayout {
  public SlidingAwareLinearLayout(final Context context) {
    super(context);
}

public SlidingAwareLinearLayout(final Context context, final AttributeSet attrs) {
    super(context, attrs);
}

public SlidingAwareLinearLayout(
        final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

public SlidingAwareLinearLayout(
        final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
}

@Override
public boolean onInterceptTouchEvent(final MotionEvent ev) {
    SlidingUpPanelLayout panel = (SlidingUpPanelLayout) getParent();
    if (ev.getAction() == MotionEvent.ACTION_DOWN 
            && panel.getPanelState() == SlidingUpPanelLayout.PanelState.ANCHORED) {
        panel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
        return true;
    }

    return super.onInterceptTouchEvent(ev);
}
}

Resource: https://github.com/umano/AndroidSlidingUpPanel/issues/476

Upvotes: 1

Related Questions