Reputation: 601
My problem is that I can't correctly set up the margin in my navigation drawer. I have tried changing margin of any view and item but it doesn't seem to work out. All I get is space between the ActionBar and NavigationDrawer (and the beginning of the page). I think that the problem is inside my ListItem layout but I am not sure. This is a photo of what I get
And this is my layout and code files.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/drawer_layout">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/refreshSites"
tools:context=".MyActivity">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sitesList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout
android:layout_width="280dp"
android:layout_height="fill_parent"
android:id="@+id/drawerPane"
android:layout_gravity="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="15dp">
<ListView android:id="@+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/white"
android:dividerHeight="0dp"
android:layout_marginLeft="15dp"
android:background="#FFF">
</ListView>
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="15dp"
android:layout_marginStart="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#222"/>
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles)); //mPlanetTitles is String array
So the question is: How do I set these margins correctly?
Upvotes: 3
Views: 8224
Reputation: 3460
Try this :
Using the help of Theme.add theme in DrawerLayout.
<style name="NavigationTheme" parent="AppTheme">
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginLeft">10dp</item>
</style>
Hope, this will help.
Upvotes: 2
Reputation: 906
Try this as item
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:padding="20dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#222"
android:text="bla bla bla" />
and main xml as this
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/drawer_layout">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/refreshSites"
tools:context=".MyActivity">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sitesList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout
android:layout_width="280dp"
android:layout_height="fill_parent"
android:id="@+id/drawerPane"
android:layout_gravity="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="@+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/white"
android:dividerHeight="0dp"
android:background="#FFF">
</ListView>
</LinearLayout>
</RelativeLayout>
Hope, this will help.
Upvotes: 1