如何设置导航抽屉右边距?

时间:2016-02-05 04:36:54

标签: android layout navigation-drawer

根据标题,如何根据Google的材料设计将导航抽屉的右边距设置为56 dp(参见下文)?我在android:layout_marginRight="56dp"的第二个视图中尝试DrawerLayout,但它看起来非常奇怪(超过56dp,与下面谷歌的素材设计图片非常不同)。

enter image description here

2 个答案:

答案 0 :(得分:0)

我建议您关注View DeawerLayout的第二navigation drawer的宽度,该宽度应在240dp to 320dp之内,

考虑到这一点,你设法在右侧给予landscape 56 dp的右边距,现在你想在angular.module('message', []) .controller('message', function($rootScope, $scope, $http, User){ //some functions ... $rootScope.user = User; $scope.message = 'Helloworld'; console.log('In Message Controller'); console.log('debug message, User activated: ' + User.activated); }) 模式中检查这个,并且会有更多的惊喜等着你

答案 1 :(得分:0)

尝试关注导航抽屉的宽度,它应介于 240dp 320dp 之间。它会自动调整右边距。

这是包含导航抽屉片段的xml文件的示例。这里片段的宽度在dimens文件夹中设置为280dp

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/container_app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <include
                android:id="@+id/app_bar"
                layout="@layout/app_bar" />

            <it.neokree.materialtabs.MaterialTabHost
                android:id="@+id/materialTabHost"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:layout_below="@+id/app_bar"
                app:accentColor="@color/colorAccent"
                app:hasIcons="true"
                app:iconColor="@android:color/white"
                app:primaryColor="@color/colorPrimary" />
        </LinearLayout>


        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@+id/materialTabHost"
            android:layout_weight="1" />
    </LinearLayout>


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.example.fragments.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>

现在这是一个示例,它是导航抽屉的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    tools:context="com.example.fragments.FragmentDrawer">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/drawerList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

如果您在dimens文件夹中设置宽度而不是硬编码,那将是一个很好的做法。

相关问题