将margin添加到navigationDrawer

时间:2017-01-28 19:53:08

标签: android

这在我之前从未发生过。基本上我有一个导航抽屉布局,当我显示一个片段时,它在所有边上留下大约10dp的空间,所以它基本上缩小了一点。

This is the result.

app_bar_main.xml:

<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.app.r6s.MainActivity"
android:background="#464646">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    layout="@layout/content_main"
    android:layout_alignParentStart="true"
    android:layout_marginTop="55dp" />

content_main.xml:

<RelativeLayout 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/show_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.app.r6s.MainActivity"
tools:showIn="@layout/app_bar_main">

片段I我试图展示:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tab_layout">

</android.support.design.widget.TabLayout>

<view
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    class="android.support.v4.view.ViewPager"
    android:id="@+id/viewpager"
    android:layout_marginTop="48dp"/>

替换片段的代码:

MyFragment fragment = new MyFragment();
        FragmentManager fm = getSupportFragmentManager();
        fm.beginTransaction().replace(R.id.show_fragments, fragment).commit();

1 个答案:

答案 0 :(得分:0)

你的content_main.xml中的填充怎么样?