Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SlidingDrawer without handle and sliding actions to content

I want to use SlidingDrawer in my application. But I have to hide the handle and have to show 20% of the content to be visible when SlidingDrawer is closed. Also I wants to assign all the sliding(touch or drag) actions of the handle to content. Please help me if any one is having some solution for this.

Please refer the following code snippet which I tried.

<View
    android:id="@id/handle"
    android:layout_width="0dip"
    android:layout_height="fill_parent" />

<LinearLayout
    android:id="@id/content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sliding_drawer" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sliding_drawer" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sliding_drawer" />
</LinearLayout>

and Here is my activity:

     import android.app.Activity;
     import android.graphics.Color;
     import android.os.Bundle;
     import android.view.View;
     import android.widget.SlidingDrawer;
     import android.widget.SlidingDrawer.OnDrawerCloseListener;
     import android.widget.SlidingDrawer.OnDrawerOpenListener;

     public class SlidingDrawerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final SlidingDrawer drawer = (SlidingDrawer) findViewById(R.id.drawer);
        drawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {

            public void onDrawerClosed() {
                // TODO Auto-generated method stub
                drawer.setBackgroundColor(Color.BLACK);
            }
        });

        drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {

            public void onDrawerOpened() {
                // TODO Auto-generated method stub
                drawer.setBackgroundColor(Color.BLUE);
            }
        });

        View content = drawer.getContent();
        content.setClickable(true);
        content.setTouchDelegate(drawer.getHandle().getTouchDelegate());
    }
}

Here I am able to hide the handle by setting width=0dip, but unable to know how to show 20% of content when SlidingDrawer is closed and set the actions to the Content of the SlidingDrawer.

I tried getting the touchDelegate of the handle and setting it to Content, but it does not work. Please help me to solve this issue.

like image 811
Raj Avatar asked Jul 24 '12 10:07

Raj


1 Answers

To have a slidingDrawer without handle, the trick is just set the width and height of the handle to 0dp. Cheers

like image 184
Jiyeh Avatar answered Nov 15 '22 01:11

Jiyeh