2017-03-12 12 views
-2

私は数日間運が無くてもそれを探していました。私は自分の断片の1つをナビゲーションドレープのように振る舞わせようとしています。誰か私にいくつかの手掛かりを与えることができますか?ナビゲーション・ドロワー/スライディング・メニューとしてのフラグメント

ここに私の断片です:

<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="pl.webtube.bejmy.fragments.NotificationFragment"> 

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

</FrameLayout> 

私は運がなくて、DrawerLayoutでそれを挿入しようとしました。

+1

試した 'DrawerLayout' XMLを表示し、正しく動作しなかった方法を正確に説明する必要があります。 –

+0

外側の 'FrameLayout'は必要ありません。フラグメントレイアウトは単なる '

答えて

2

ここでは、画面の左側に引き出しとして設定されたフラグメントを含むアクティビティレイアウトの例を示します。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/drawer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     tools:openDrawer="start"> 

    <!-- Things "under the drawer" --> 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

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

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

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

     <!-- "Main Activity content", like a FrameLayout to load Fragments --> 
     <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/container"/> 
    </LinearLayout> 

    <!-- The left drawer; change width to adjust size --> 
    <LinearLayout 
      android:layout_width="64dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:background="@android:color/background_light" 
      android:fitsSystemWindows="true" > 
     <fragment 
       android:id="@+id/fragment_drawer" 
       android:name="com.example.NavigationDrawerFragment" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1"/> 

    </LinearLayout> 


</android.support.v4.widget.DrawerLayout> 

com.example.NavigationDrawerFragmentの中に他のビューをそのままロードすることができます。それはリストである必要はありません。

+1

ありがとう!完璧に動作する – AndroidBegginer

関連する問題