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);
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>