用于布局的Android抽象活动

时间:2013-09-16 13:03:57

标签: android android-layout

是否可以有一个定义布局(导航等)的抽象活动和定义活动内容的子类? xml布局文件怎么样?

我的意思是我有一个xml

 <xxx.DefaultNavigationDrawer xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" >

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

    <!-- Fragment contents go in here -->

</FrameLayout>

<ListView
    android:id="@+id/navigation_drawer_list"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout_weight="1"
    android:background="@drawable/calendar"
    android:choiceMode="singleChoice"
    android:divider="@color/calendar_divider"
    android:dividerHeight="1dp" />

</xxx.DefaultNavigationDrawer>

我希望我的所有活动都有这样的布局。唯一会改变的是标记。

1 个答案:

答案 0 :(得分:1)

您可以在基础Activity课程中设置布局,然后在衍生活动的onCreate中调用FragmentManager.replace(),将FrameLayout的内容替换为您的片段