Android DrawerLayout does not work when using TOP and BOTTOM gravities

I just play with the new DrawerLayout recently included in the support library. I implemented a simple one, for example, with several boxes, while I used START and END as gravity, it all worked like a charm, but when I try to add a box using TOP or BOTTOM gravities, it will work.

Can I use it for drawers above and below?

Below is the full code of my activity and the xml layout in working condition; If I try to change this:

<ListView android:id="@+id/right_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="end" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#007799"/> 

into this (note the changes to layout_width, layout_height and layout_gravity):

 <ListView android:id="@+id/right_drawer" android:layout_width="match_parent" android:layout_height="300dp" android:layout_gravity="bottom" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#007799"/> 

and line:

 this.drawer.openDrawer(GravityCompat.START); 

info this:

 this.drawer.openDrawer(Gravity.BOTTOM); 

when i get the following error:

 05-16 05:22:33.981 1503-1503/es.luixal.test E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{es.luixal.test/es.luixal.test.MainActivity}: java.lang.IllegalArgumentException: View android.widget.RelativeLayout{42664c80 VE.... ......I. 0,0-0,0} is not a sliding drawer at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalArgumentException: View android.widget.RelativeLayout{42664c80 VE.... ......I. 0,0-0,0} is not a sliding drawer at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:970) at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1003) at es.luixal.test.MainActivity.onCreate(MainActivity.java:30) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) ... 11 more 

Any clues why I can't use other gravity?

Thanks!

MainActivity.java

 package es.luixal.test; import android.app.Activity; import android.os.Bundle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends Activity { private DrawerLayout drawer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // filling list items: ListView listView = (ListView)findViewById(R.id.left_drawer); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[]{ "MenuItem 1", "MenuItem 2", "MenuItem 3" }); listView.setAdapter(adapter); // this.drawer = (DrawerLayout)findViewById(R.id.drawer_layout); this.drawer.openDrawer(GravityCompat.START); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override protected void onStart() { super.onStart(); } } 

activity_main.xml

  <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="match_parent" android:text="Hi!" /> </RelativeLayout> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#44aa00"/> <ListView android:id="@+id/right_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="end" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#007799"/> </android.support.v4.widget.DrawerLayout> 
+8
android android-layout
source share
3 answers

There is no official link to DrawerLayout to use "Bottom" or "Top" Gravity - Source

public void openDrawer (int gravity)

Open the specified box, reviving it out of sight.

Gravity Parameters

Gravity.LEFT to move the left drawer or Gravity.RIGHT to the right. You can also use GravityCompat.START or GravityCompat.END.

If you want to use other visual effects - use a different library

+6
source share

We recently implemented this functionality in a Umano application and opened it:

https://github.com/umano/AndroidSlidingUpPanel

+11
source share

Simon Vig Therkildsen's Menu-Drawer library works well as a standard menu drawer, but also supports top and bottom drawers. His sample application provides examples of how to implement a menu with TOP / BOTTOM effects.

+1
source share

All Articles