2013-09-16 99 views
0

是否有可能具有定义布局(导航等)的抽象活动和定义活动内容的子类? XML布局文件怎么样?Android布局抽象活动

我的意思是我有一个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

您可以在基地Activity类设置你的布局,然后在你的派生活动的onCreate你可以调用FragmentManager.replace()与片段取代您FrameLayout的内容。

+0

我必须使用碎片吗? – kboom

+0

由于你想插入一个片段,你如何避免使用片段呢? –

+0

我在问的是是否有另一种方式:)。你的答案完全没问题。 – kboom