Reputation:
I'm programming my first little app. In this app i'm using two drawer, one on the right and one on die left side:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/relLayout"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:background="#D1933C"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<com.schnapsidee.app.CustomWebView
android:id="@+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/space1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/space3"
android:scrollbars="vertical"
android:text="@string/fail"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/black" />
<android.support.v7.widget.Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="62dp" />
<android.support.v7.widget.Space
android:id="@+id/space2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<android.support.v7.widget.Space
android:id="@+id/space3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp" />
<TextView
android:id="@+id/seitenZahl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textColor="@color/black"
android:textSize="22sp" />
</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="#111"
android:width="0dp"/>
<ListView
android:id="@+id/right_drawer"
android:layout_width="240dp"
android:layout_height="800dp"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@drawable/pergament"
android:scrollbars="vertical"
android:drawSelectorOnTop="false"
/>
I use them like:
mDrawerItemLeft = getResources().getStringArray(R.array.sidebar_array_left);
mDrawerItemRight = getResources().getStringArray(R.array.sidebar_array_right);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerListLeft = (ListView) findViewById(R.id.left_drawer);
mDrawerListRight = (ListView) findViewById(R.id.right_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
mDrawerListLeft.setAdapter(new Adapter(this, R.layout.drawer_list_item_left,
mDrawerItemLeft));
mDrawerListRight.setAdapter(new Adapter(this, R.layout.drawer_list_item_right,
mDrawerItemRight));
mDrawerListLeft.setOnItemClickListener(new LeftDrawerItemClickListener());
mDrawerListRight.setOnItemClickListener(new RightDrawerItemClickListener());
My problem is, that i dont want the right Drawer to use the complete screen-height. I just want it to use a part of it like the red part in this picture: https://i.sstatic.net/IdXAf.jpg
Any idea how i can do this?
Thanks in advance!
Upvotes: 1
Views: 118
Reputation: 1811
There is no need for the Navigation drawer to specifically be a ListView only, you can use any View/ViewGroup for this purpose just set the gravity="end" to make it right navigation drawer.
<ListView
android:id="@+id/right_drawer"
android:layout_width="240dp"
android:layout_height="800dp"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@drawable/pergament"
android:scrollbars="vertical"
android:drawSelectorOnTop="false" />
Change above code to this:
<RelativeLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end">
<ListView
android:id="@+id/right_drawer"
android:layout_width="match_parent"
android:layout_height="500dp"
android:choiceMode="singleChoice"
android:layout_centerVertical="true" />
</RelativeLayout>
Set the other attributes of ListView as needed, and change the height to something shorter than 800dp because 800dp is quite long height and will definitely be larger than actual screen height on many devices.
Upvotes: 2
Reputation: 495
use in navigation drawer
android:layout_height="0dp"
android:layout_weight="1"
using this, thing you should know ... navigation drawer take height of its content. so it is taking listView,s height .. give height to your listview(as your requirement) then give listView Background "transparent as written below
android:layout_height="as you want"
android:background="@color/tranparent"
to make it under your header then take linear Layout and write navigation drawer,s code after you header .. if you are Relative layout then use android:layout_below="your header id"
in your navigation drawer.
Upvotes: 0
Reputation: 8023
Rather than using a ListView, use a layout e.g. Linear, Relative and then place the ListView inside that layout. If you place the layout as the last element in your xml, the whole layout becomes the layout of the navigation drawer. You can then position your Listview inside the layout any way you want.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#111"/>
<!-- The navigation drawer -->
<RelativeLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start">
<!-- Position this list view inside the relative layout the way you want -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
Upvotes: 0
Reputation: 2287
give width 0dp to both views and add android:layout_weight="1" in both views.
Upvotes: 0