Search code examples
androidslidingdrawersliding

ScrollView in second panel not working


I have an Activity that uses AndroidSlidingUpPanel. Now, everything works perfect. However, I would like to add a ScrollView on my second panel to add the same functionality like Maps or Google Music:

For instance,

enter image description here

When the user has a list of directions, he/she may pull up the drawer and scroll the complete instructions.

Now, my attempt:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >

    <ScrollView
        android:id="@+id/card_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

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

            <it.gmariotti.cardslib.library.view.CardView
                android:id="@+id/food_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_marginTop="12dp"
                android:animateLayoutChanges="true" />

            <View
                android:layout_width="match_parent"
                android:layout_height="15dp" />
        </LinearLayout>
    </ScrollView>

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

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

            <TextView
                android:id="@+id/name_slide"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:paddingLeft="10dp"
                android:text="@string/slide_up"
                android:textSize="14sp" />
        </LinearLayout>

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

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

            <it.gmariotti.cardslib.library.view.CardView
                android:id="@+id/food_nutrition_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:animateLayoutChanges="true" />

            <View
                android:layout_width="match_parent"
                android:layout_height="15dp" />
        </LinearLayout>
        </ScrollView>


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

This, displays fine my content, but does not add the scroll view for the second panel. What can I do?

Note: According to the documentation of AndroidSlidingUpPanel, there can only be two children under its view. I use a LinearLayout as the second child because its the only way that I have found to display the drawer. For instance, that TextView would be in the place of the content of the estimated time (drawer) from Maps.

Thanks


Solution

  • Fixed it by adding an id to the Parent of the Title, and adding this to my code:

    layout.setDragView((LinearLayout) findViewById(R.id.scrolled_view));
    

    New .xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom" >
    
        <ScrollView
            android:id="@+id/card_scrollview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
    
                <it.gmariotti.cardslib.library.view.CardView
                    android:id="@+id/food_card"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="1dp"
                    android:layout_marginRight="1dp"
                    android:layout_marginTop="12dp"
                    android:animateLayoutChanges="true" />
    
                <View
                    android:layout_width="match_parent"
                    android:layout_height="15dp" />
            </LinearLayout>
        </ScrollView>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#eee"
            android:clickable="true"
            android:focusable="false"
            android:orientation="vertical" >
    
            <LinearLayout
                android:id="@+id/scrolled_view"
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:orientation="horizontal" >
    
                <TextView
                    android:id="@+id/name_slide"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:text="@string/slide_up"
                    android:textSize="14sp" />
            </LinearLayout>
    
            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
    
                <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
    
                <it.gmariotti.cardslib.library.view.CardView
                    android:id="@+id/food_nutrition_card"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="12dp"
                    android:animateLayoutChanges="true" />
    
                <View
                    android:layout_width="match_parent"
                    android:layout_height="15dp" />
            </LinearLayout>
            </ScrollView>
    
    
        </LinearLayout>
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>