设置NavigationDrawer项目的边距 [英] Setting a margin for NavigationDrawer items

查看:82
本文介绍了设置NavigationDrawer项目的边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我无法在导航抽屉中正确设置边距.我尝试更改任何视图和项目的边距,但似乎无法解决.我所得到的只是ActionBar和NavigationDrawer(以及页面的开头)之间的空间.我认为问题出在我的ListItem布局内,但我不确定.这是我所得到的照片

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>

drawer_list_item.xml

<?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"/>

我与NavigationDrawer一起工作的代码

 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

所以问题是:如何正确设置这些边距?

推荐答案

尝试作为项目

<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" />

和主要的xml

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

希望,这会有所帮助.

这篇关于设置NavigationDrawer项目的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆