Android: Sliding Drawer

Go To StackoverFlow.com

0

I am using a sliding drawer on my application (actually its a Panel). I would like to make that panel scrollable. How can I do that?

Here is the xml code for that part:

  <org.miscwidgets.widget.Panel
        android:id="@+id/rightPanel3"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="right"
        panel:animationDuration="500"
        panel:closedHandle="@android:drawable/ic_menu_directions"
        panel:content="@+id/panelContent"
        panel:handle="@+id/panelHandle"
        panel:linearFlying="true"
        panel:openedHandle="@android:drawable/ic_menu_directions"
        panel:position="right"
        panel:weight="75%p" >

        <Button
            android:id="@+id/panelHandle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="20dip" />

        <TextView
            android:id="@+id/panelContent"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:background="#000000"
            android:gravity="left"
            android:padding="4dip"
            android:text="Directions"
            android:textColor="#eee"
            android:textSize="16dip"
            android:textStyle="bold" />
    </org.miscwidgets.widget.Panel>
2012-04-04 18:17
by phedon rousou
we're going to need more info to be able to help you. Perhaps post the code for your custom Panel object, and maybe be a little bit more clear about what you are hoping to achieve. "I want to make that panel scrollable" doesn't really give us a lot to go from - FoamyGuy 2012-04-04 18:23
Is the acceptable answer compatible with Android 6.0 - Ahmed 2015-12-22 20:37


1

To do what you are looking for is simple. You will want to wrap your TextView @+id/panelContent inside of a ScrollView. This will allow the content inside the open SlidingDrawer to be scrolled. Here is the code for what you are looking to do.

<org.miscwidgets.widget.Panel
    android:id="@+id/rightPanel3"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="right"
    panel:animationDuration="500"
    panel:closedHandle="@android:drawable/ic_menu_directions"
    panel:content="@+id/panelContent"
    panel:handle="@+id/panelHandle"
    panel:linearFlying="true"
    panel:openedHandle="@android:drawable/ic_menu_directions"
    panel:position="right"
    panel:weight="75%p" >

    <Button
        android:id="@+id/panelHandle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="20dip" />

    <ScrollView
        android:id="@+id/panelContent"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        andrid:fillViewport="true" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:background="#000000"
                android:gravity="left"
                android:padding="4dip"
                android:text="Directions"
                android:textColor="#eee"
                android:textSize="16dip"
                android:textStyle="bold" />
   </ScrollView>
</org.miscwidgets.widget.Panel>
2012-04-04 18:39
by Bobbake4
what does the fillViewport do - phedon rousou 2012-04-04 18:47
fillViewport causes the content inside of the scrollview to be stretched to fill the area of the scrollview. This will only make a difference if the content is not large enough to actually fill the scrollview - Bobbake4 2012-04-04 18:49
(Edit) Thanks for your answer. Basically, before applying the change you propose, I have access to the textView through this code: TextView tv = (TextView) directionPanel.getContent(); And I use tv.setText to set the text to whatever I want. But now, the panelContent is a scrollview, How can I set the textView text - phedon rousou 2012-04-04 19:10
You want to give the TextView a new id and you can use your normal call to findViewById(int id) to get a reference to the TextView so you can set the text on it - Bobbake4 2012-04-04 19:46
Thanks, I did that alread - phedon rousou 2012-04-04 19:58
Ads