简体   繁体   中英

Android: Two FragmentActivities in one layout

Is it somehow possible to host two FragmentActivities in one layout?

For example, if I have following layout, can I host one FragmentActivity in container1 and one FragmentActivity in container2?:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >


<FrameLayout
    android:id="@+id/container1"
    android:layout_width="match_parent"
    android:layout_height="150dp" >
</FrameLayout>

<FrameLayout
    android:id="@+id/container2"
    android:layout_width="match_parent"
    android:layout_height="150dp" >

</FrameLayout>

If this is not possible, can I have one FragmentActivity that loads two different fragments and displays one in container1 and one in container2?

You are a bit confused. Layouts doesn't contain activities, activities contain a layout. In your layout you can put View s and fragments, so yes, it is possible to load two fragments in one FragmentActivity , or rather it is the only way to achieve what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM