2016-06-27 7 views
0

Ich baue eine Android-App mit der Navigationsschublade Vorlage. Ich habe eine Klasse mit dem Namen MainActivity mit einem Layout bekommt, dass meine app_bar_main.xml umfasst, die wie folgt aussieht:App-Leiste deckt Fragment

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.erik.fuelbuddy.MainActivity"> 

<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> 

<FrameLayout 
    android:id="@+id/fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" > 

</FrameLayout> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_dialog_email" /> 

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

fragment_container verwendet werden, um Fragmente anzuzeigen. Hier ist einer von ihnen als Beispiel:

<FrameLayout 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" 
tools:context="com.erik.fuelbuddy.NearbyFragment" 
> 

<!-- TODO: Update blank fragment layout --> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Nearby" /> 

</FrameLayout> 

jedoch die Textview unterhalb der Symbolleiste angezeigt, die durch das Hinzufügen einer Polsterung, um es bestätigt werden können, zum Beispiel 100dp.

Warum ist das und wie kann ich es beheben?

Antwort

1

Ich löste es durch diese Zeile hinzu:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

an dem Behälter FrameLayout etwa so:

<FrameLayout 
    android:id="@+id/fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

</FrameLayout> 
1

Versuchen Sie ein Layout in hinzuzufügen zwischen fügen Sie den Inhalt

Mittlere Sie direkt zeigen Sie die Symbolleiste, die die Symbolleiste direkt das vollständige Layout der Inhaltsansicht enthält, so dass Sie ein Layout nehmen sollten zwischen nehmen Sie Ihre Symbolleiste und Container.

anzeigen Layout Sie so wollen, aber nehmen Sie die InhaltAlle in das Layout für die Show

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.erik.fuelbuddy.MainActivity"> 


<LinearLayout> 
android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 


<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> 

<FrameLayout 
    android:id="@+id/fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" > 

</FrameLayout> 



<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_dialog_email" /> 
</LinearLayout> 



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