Nameishi
Nameishi

Reputation: 305

Android studio Multi Fragments in 1 activity implementation

Hi I am hoping someone can clear some confusion I have from reading this site (Section 4.2) http://www.vogella.com/tutorials/AndroidFragments/article.html and some code I seen via Youtube https://www.youtube.com/watch?v=oN2AAhaOBf8

My Question: One Activity and two fragments..but you only want to see one fragment at a time. within the activity_main xml file instead of having

    <fragment
        android:id="@+id/message_fragment"
        android:name="com.example.android.fragments.MessageListViewFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="top" />

    <fragment
        android:id="@+id/send_fragment"
        android:name="com.example.android.fragments.SendMessageFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="bottom" />  

Should I replace each fragment with FrameLayout? or Would i just have one FrameLayout...I have seen both, not sure which one is correct. Thank you, Im just trying to understand..From research I am assuming FrameLayout allows only one fragment to appear at a time??

Upvotes: 1

Views: 109

Answers (1)

Jaydev
Jaydev

Reputation: 1812

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view... You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child.

You can use android:visibility tag and toggle between visible/invisible on need basis. This would work irrespective of any layout.

Upvotes: 1

Related Questions