0

I want to create sliding drawer in android which should be placed on top of the activity and should be open from top to bottom like android notification panel. How to achieve this?

user3391170
  • 101
  • 2
  • 7

2 Answers2

1

The default SlidingDrawer class doesn't allow this. You can use the Panel class from here to get something very similar though OR set the rotation of 180ΒΊ for the SlidingDrawer, the content and the handle. Note : android:rotation is support on API > Level 11

http://www.ohloh.net/p/android-misc-widgets
https://github.com/IanDarwin/Android-Cookbook-Examples/tree/master/SlidingDrawer-Topdown

Reference

Community
  • 1
  • 1
Elshan
  • 7,339
  • 4
  • 71
  • 106
  • I am not able to run cookbook example its giving me error as 03-02 16:44:06.023: E/AndroidRuntime(21584): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.slidingdrawer/com.example.slidingdrawer.MainActivity}: java.lang.RuntimeException: Your Panel must have a View whose id attribute is 'R.id.panelHandle' – user3391170 Mar 02 '15 at 11:14
1

If you want to have sliding drawer from top to bottom then just copy pase this code in your project, it is 100% working code.

main.xml

<?xml version="1.0" encoding="utf-8"?>

 <RelativeLayout   
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:background="#d3d3d3"
    >
    <SlidingDrawer
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/slidingDrawer"
    android:layout_width="wrap_content"
    android:layout_height="300dp"
    android:content="@+id/content"
    android:gravity="center_horizontal"
    android:handle="@+id/handle"
    android:orientation="vertical"
    android:rotation="180" >

    <LinearLayout
        android:id="@+id/handle"
        android:layout_width="fill_parent"
        android:layout_height="40dp" 
        android:gravity="right"
       android:background="@+drawable/drawer_bk"
           >

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@+drawable/drawer1" />



    </LinearLayout>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="45dp" >

    <RelativeLayout
        android:id="@+id/rel1"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="10dp"
        android:rotation="180" >

        <ImageView
            android:id="@+id/ImageView04"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:onClick="visit"
            android:src="@drawable/visit_icon" />

        <ImageView
            android:id="@+id/ImageView03"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_alignParentTop="true"
            android:layout_marginRight="35dp"
            android:layout_toLeftOf="@+id/ImageView04"
            android:onClick="contact_us"
            android:src="@drawable/contact_icon" />

        <ImageView
            android:id="@+id/ImageView02"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="35dp"
            android:layout_toRightOf="@+id/ImageView04"
            android:onClick="logout"
            android:src="@drawable/singout_icon" />
    </RelativeLayout>


</RelativeLayout>

  </SlidingDrawer>

MainActivity.java

 public class MainActivity extends Activity 
 {

/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 4000;
Button slideButton,b1, b2,b3,b4;
SlidingDrawer slidingDrawer;

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //slideButton = (Button) findViewById(R.id.slideButton);
    slidingDrawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);
     slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
        @Override
        public void onDrawerOpened()
        {
           // slideButton.setBackgroundResource(R.drawable.down_arrow_icon);
            slidingDrawer.setBackgroundResource(R.drawable.hd_img_1);
        }
    });

    slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() 
    {
        @Override
        public void onDrawerClosed() 
        {

          //  slideButton.setBackgroundResource(R.drawable.upwar_arrow_icon);
            slidingDrawer.setBackgroundColor(Color.TRANSPARENT);
        }
    });

   }
}
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81