Android 为NavigationDrawer项目设置边距
我的问题是我不能在导航抽屉中正确设置边距。我尝试过改变任何视图和项目的边距,但似乎并没有成功。我得到的只是ActionBar和NavigationDrawer之间的空间(以及页面的开头)。我认为问题出在我的ListItem布局中,但我不确定。这是我得到的一张照片 这是我的布局和代码文件 主布局Android 为NavigationDrawer项目设置边距,android,navigation-drawer,Android,Navigation Drawer,我的问题是我不能在导航抽屉中正确设置边距。我尝试过改变任何视图和项目的边距,但似乎并没有成功。我得到的只是ActionBar和NavigationDrawer之间的空间(以及页面的开头)。我认为问题出在我的ListItem布局中,但我不确定。这是我得到的一张照片 这是我的布局和代码文件 主布局 抽屉列表项.xml 我的一段与NavigationDrawer一起工作的代码 mDrawerLayout=(抽屉布局)findViewById(R.id.drawer\u布局); mDrawer
抽屉列表项.xml
我的一段与NavigationDrawer一起工作的代码
mDrawerLayout=(抽屉布局)findViewById(R.id.drawer\u布局);
mDrawerList=(ListView)findViewById(R.id.left\u抽屉);
mDrawerList.setAdapter(新阵列适配器,
R.布局图.抽屉(列表项,MPLANETITLES)//mPlanetTitles是字符串数组
所以问题是:如何正确设置这些页边距?尝试将此作为项目
<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>
希望,这会有所帮助。试试这个:
使用Theme.add的帮助在抽屉布局中添加主题
<style name="NavigationTheme" parent="AppTheme">
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginLeft">10dp</item>
</style>
5dp
10dp
希望这会有所帮助 不要使用边距,而是使用填充,我认为这会有所帮助。这正是我要找的。问题在于使用边距而不是填充。老实说,很遗憾我之前不知道这两者的区别,但我希望现在我会记住:)
<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" />
<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>
<style name="NavigationTheme" parent="AppTheme">
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginLeft">10dp</item>
</style>