2016-12-27 8 views
0

나는이 라이브러리를 사용하고 있습니다 :내 사용자 정의 조각이있는 NavigationDrawer?

new DrawerBuilder() 
     .withActivity(this) 
     .withDrawerGravity(Gravity.END) 
     .append(result); 

나는 또한 RecyclerView과 몇 가지 추가 볼 수있는 조각이 있습니다 https://github.com/mikepenz/MaterialDrawer 나는에 NavigationDrawer이를 탐색 항목과 내가 추가 서랍이 오른쪽에서 왼쪽으로 내부 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:background="@color/listBackground"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/contactsList" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    tools:listitem="@layout/fragment_contacts_item" /> 

<LinearLayout 
    android:id="@+id/layoutNoContacts" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_centerVertical="true" 
    android:orientation="vertical" 
    android:paddingBottom="128dp" 
    android:visibility="gone"> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="100dp" 
     android:scaleType="fitCenter" 
     app:srcCompat="@drawable/sad" /> 
</LinearLayout> 

이 단편은 레이아웃을 팽창 및 RecyclerView에 항목을 추가한다.

이 내 메인 레이아웃입니다 :

<?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:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/appbar_padding_top" 
    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"> 

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

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:background="@color/listBackground"> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="80dp" 
     android:clickable="true" /> 
</RelativeLayout> 

가 어떻게 대신 탐색 항목의 항상 NavigationDrawer에서 내 연락처를 표시이 사용자 정의 조각을 보일 수 있는가?

답변

2

MaterialDrawer 대신 Android Drawer Layout을 사용할 수 있습니다. 사용자 지정 조각이있는 매력처럼 작동합니다.

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!-- The main content view --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <!-- The navigation drawer --> 
    <fragment android:name="com.example.YourFragment" 
     android:id="@+id/left_drawer" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" /> 
</android.support.v4.widget.DrawerLayout> 
+0

도움을 주셔서 감사합니다. 내 기본 레이아웃 파일을 추가했는데 어디에 추가해야합니까? 그리고 어떻게 그 안에 내용을 넣을 수 있을까요? 정규 FragmentTransaction 만 있으면됩니까? – user754730

+1

조각은'android : name' 속성에 따라 정적으로 추가됩니다. – EpicPandaForce

+1

이 레이아웃은 서랍을 제시해야하는 활동 (활동 내용 레이아웃)에서 사용해야합니다. 조각을 동적으로 추가하려면 태그의 내용을 로 대체하고 정규 FragmentTransaction으로이 프레임 레이아웃에 Fragment를 추가해야합니다. 조각 문서에서 자세한 내용보기 : https://developer.android.com/guide/components/fragments.html –