1

我正在使用 ActionsContentView 库作为侧边菜单栏。

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

最初我尝试在支持库中使用 Google 的 NavigationDrawer 对象。但我放弃了它,因为我需要视图的某些部分的非列表视图类型的布局。

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

无论如何,我需要 ActionsContentView 库已经提供的灵活性

我可以在 NavigationDrawer 中使用非列表视图吗?

4

1 回答 1

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 方法,该方法将使用内容片段填充活动框架。在您的子类中调用 setFrameContent 而不是 onCreate 方法中的 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 做任何事情。

于 2013-07-09T16:10:36.423 回答