2017-10-29 1 views
0

Android layoutVerschieben umfasst unter dem relativen Layout

Ich versuche, die include unter dem Relative-Layout zu verschieben (mit einer Symbolleiste im Innern). Jetzt, wie Sie aus dem Bild sehen können, überlappen sie sich.

Hier ist mein Beispielcode:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/white" 
android:fitsSystemWindows="true"> 

<include layout="@layout/content_main" /> 

    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     app:layout_collapseMode="pin" 
     app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
    </RelativeLayout> 

</android.support.design.widget.CoordinatorLayout> 
+1

MarginTop geben, wie Sie Breite der Symbolleiste haben –

+0

wenn ich gebe 'marginTop' in die Symbolleiste dann wird die Symbolleiste positioniert sind, aber ich möchte, dass sie nicht überlappen –

+0

nein nein nicht Rand, sondern Symbolleiste geben die Layout, das Sie einschließen, machen das gleiche –

Antwort

0

Platzieren Sie Ihre Symbolleiste in einem AppBarLayout.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/white"> 

<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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
</android.support.v7.widget.Toolbar> 

<include layout="@layout/content_main" /> 

</android.support.design.widget.CoordinatorLayout> 
Verwandte Themen