2013-07-08 23 views
1

我正在使用ActionsContentView库作为侧面菜单栏。带有自定义列表视图和非列表项的导航画笔

https://play.google.com/store/apps/details?id=sample.actionscontentview

起初我尝试使用谷歌的NavigationDrawer对象的支持库。但是我放弃了它,因为我需要在视图的某些部分使用非listview类型的布局。

无论如何,我想知道这个推理是否有缺陷。我的部分菜单是使用非列表视图和一些相当复杂的自定义布局,这些布局可能会在滚动视图中动态添加,或者最终可能最终会成为listview中的自定义适配器。

无论如何,我需要ActionsContentView库已经提供

我可以使用在NavigationDrawer非列表视图的灵活性?

回答

5

你可以。

DrawerLayout是一个布局,其中包含2个布局 - 1是菜单,另一个包含您的内容。

这意味着您可以在菜单抽屉中放置一个片段,并将其填入任何您想要的内容。

<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_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<FrameLayout 
    android:id="@+id/activityFrame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
</FrameLayout> 

<FrameLayout 
     android:id="@+id/drawer" 
     android:layout_width="320dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@drawable/backgound_menu" > 

    <fragment 
      android:id="@+id/menuFragment" 
      android:name="com.foo.bar.fragment.MenuFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:layout="@layout/menu_fragment" /> 
</FrameLayout> 

您可以通过一个基类的活动,您的菜单活动扩展做到这一点。然后在基本活动中添加一个setFrameContent方法,该方法将使用内容片段填充活动框架。在你的子类中,在onCreate方法中调用setFrameContent而不是setConentView。

基本活动

@Override 
protected void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    setContentView(R.layout.activity_fragment_drawer); 
} 

public void setFrameContent(int activityLayout) { 
    mContent.addView(
      getLayoutInflater().inflate(
        activityLayout, 
        mContent, false), 
      new LinearLayout.LayoutParams(DrawerLayout.LayoutParams.MATCH_PARENT, 
        DrawerLayout.LayoutParams.MATCH_PARENT)); 
} 

子类

@Override 
protected void onCreate(Bundle bundle) { 
super.onCreate(bundle); 
    setContentView(R.layout.activity_fragment_content); 
} 

从那里,你可以自由地做任何与MenuFragment。

+0

你能举一个完整的例子@Phil H –