2016-06-27 6 views
0

私はナビゲーションドロワーテンプレートでアンドロイドアプリを構築しています。アプリケーションバーはフラグメントをカバーします

<?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がフラグメントを表示するために使用されます。私はこのようになります私のapp_bar_main.xmlを含んレイアウトでMainActivityという名前のクラスを持っています。ここでは一例として、そのうちの一つです。しかし

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

のTextViewは、インスタンス100dpのために、それにパディングを追加することによって確認することができるツールバーの下に表示されています。

これはなぜですか、どのように修正できますか?

答えて

1

私はこの行を追加することで、それを解決:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

をコンテナにはそうのようでframeLayout:

<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

は直接あなたの平均コンテンツ

を追加する間にレイアウトを追加しようツールバーには完全なコンテンツビューのレイアウトが直接表示されるので、ツールバーとコンテナの間をレイアウトする必要があります。

は次のようにしたいレイアウトを示すがcontentviewショーのためにレイアウトに

<?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> 
を取ります
関連する問題