1

I use this library, https://github.com/umano/AndroidSlidingUpPanel, and I put a listview inside, but it does not work, no scrolling, why? Not only listview, the entire layout does not roll, nor with textview, nor image, nothing. Here is my xml code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Detalhe_linha" 

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


   <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Próximo onibûs sai do ponto final em" />

    <TextView
        android:id="@+id/txtProx"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="X minutos"
        android:layout_gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <GridView
        android:id="@+id/tabelaHorarios"
        android:layout_width="315dp"
        android:layout_height="match_parent"
        android:layout_x="0dp"
        android:layout_y="123dp"
        android:layout_gravity="center"
        android:numColumns="3" >

    </GridView>
</LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#CCCC"
            android:orientation="vertical">

              <TextView
                android:layout_width="match_parent"
                android:layout_height="34dp"
                android:gravity="center|bottom"
                android:text="Itinerário"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/brought_by"
                android:layout_width="match_parent"
                android:layout_height="34dp"
                android:gravity="center|top"
                android:text="Arraste para cima"
                android:textSize="14sp"
                android:autoLink="web" />


               <TextView
                android:id="@+id/itinerarios"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center|top"
                android:text=""
                android:textSize="17sp"
                android:autoLink="web" />

        </LinearLayout> 
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>
</LinearLayout>

By the way, sorry for my bad english.

Malinosqui
  • 2,222
  • 2
  • 13
  • 11

3 Answers3

3

I found that the issue is that SlidingUpPanelLayout intercepts touch events (onInterceptTouchEvent). My solutions was rewriting (or overriding) method isDragViewHit which is checked in case MotionEvent.ACTION_DOWN and can potentially cancel intercepting for a given touch event.

Here is my solution which cancels intercepting if panel is expanded allowing click/scroll for expanded child panel. This also means you can't slide down the expanded panel. I implemented collapsing of panel on a button click. Check the implementation and it will give you ideas what is possible.

private boolean isDragViewHit(int x, int y) {
    if(isExpanded()){
        //don't intercept touch if panel expanded
        return false;
    }
    else{
        //original implementation - only allow dragging on mDragView
        View v = mDragView != null ? mDragView : mSlideableView;
        if (v == null) return false;
        int[] viewLocation = new int[2];
        v.getLocationOnScreen(viewLocation);
        int[] parentLocation = new int[2];
        this.getLocationOnScreen(parentLocation);
        int screenX = parentLocation[0] + x;
        int screenY = parentLocation[1] + y;
        return screenX >= viewLocation[0] && screenX < viewLocation[0] + v.getWidth() &&
                screenY >= viewLocation[1] && screenY < viewLocation[1] + v.getHeight();
    }
}
MSquare
  • 6,311
  • 4
  • 31
  • 37
  • @MSquare-Actually i have Listview in SlidingUpPanel. There's a button on each listview item. I want to collapse panel on button click on perticular list view item. I think setDragView() is method for collapsing panel. But i can't understand how can i implement in my adapter class? Please tell me how can i do that. Thanks in Advance. – Dhruv Apr 16 '14 at 07:19
  • @MSquare where to add this method and where to call it? – Shreyash Mahajan Dec 26 '14 at 07:22
  • @iDroidExplorer, I checked the github history for AndroidSlidingUpPanel .java . The method isDragViewHit was removed in the commit from 23.12.2013. https://github.com/umano/AndroidSlidingUpPanel/commit/5986bd3cd947775ecce28878d3e7562287804bfa – MSquare Dec 29 '14 at 12:16
3

a better way is to define a DragView. I use a textView and it slide only when I touch the textView. All the other views intercepts clicks !

Juliatzin
  • 18,455
  • 40
  • 166
  • 325
1

I'm leaving my way of doing it here in case anyone else stumbles upon this situation.

A much cleaner solution, as Juliatzin states, is to define a DragView with the method setDragView(...) rather than going about overriding a the classes method.

To do so, in your xml file where you state the layout of your SlidingUpPanel menu, you should state a View, whatever you want, with an id, for example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent" >

 <LinearLayout ...>
     MAIN CONTENT
 </LinearLayout>

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#eee"
        android:orientation="vertical"
        android:clickable="true"
        android:focusable="false">

     Views you want to be able to click on your menu...

     <Button //This view will be the one that when touched on your SlidingUpPanel, said panel
             //will close and let the other Views capture click events. You could give it some
             //style so as to have it blend into the SlidingUpPanel if you don´t want it visible
        android:id="@+id/close_SlidingUpPanel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       />

</LinearLayout>    

And in the activity where you set up the SlidingUpPanel you would do this:

 SlidingUpPanelLayout layout = (SlidingUpPanelLayout) findViewById(R.id.sliding_up_panel);
 layout.setDragView(findViewById(R.id.close_SlidingUpPanel));

Hope it was clear and that it helps. By default, I believe the DragView is set to null which means that any part of the SlidingUpPanel makes it available for drag, and that´s why it closes when you try to "click" on one of it's childs.

Chayemor
  • 3,577
  • 4
  • 31
  • 54