android-为NavigationDrawer项目设置边距

android-为NavigationDrawer项目设置边距,第1张

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

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

这是我的布局和代码文件.

主要布局

<androID.support.v4.Widget.DrawerLayoutxmlns: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.SwipeRefreshLayoutandroID:layout_height="match_parent"androID:layout_wIDth="match_parent"androID:ID="@+ID/refreshSites"tools:context=".MyActivity"><androID.support.v7.Widget.RecyclerVIEwxmlns: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>

抽屉式清单_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.DrawerLayoutxmlns: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>

希望这会有所帮助.

总结

以上是内存溢出为你收集整理的android-为NavigationDrawer项目设置边距全部内容,希望文章能够帮你解决android-为NavigationDrawer项目设置边距所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1078656.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存