2016-06-27 10 views
2
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    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/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <include layout="@layout/nav_header_main" /> 
     </LinearLayout> 

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


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     View child = getLayoutInflater().inflate(R.layout.app_bar_main, null); 
     drawer.addView(child); 

我使用此代碼以編程方式將不同的孩子添加到抽屜佈局。當我以編程方式添加孩子意味着導航抽屜工作不正常,我的意思是它可以拖出來,但不能拖入。當我接觸側面意味着它正在關閉。任何人都可以知道如何解決這個問題。提前致謝。如何以編程方式在DrawerLayout中包含佈局並平滑拖動導航​​視圖?

回答

1

而不是包含在抽屜佈局中嘗試包含在協調器佈局中。

+0

謝謝,它的工作。 –

相關問題