Android Two Fragments in Same Activity

前端 未结 1 1008
[愿得一人]
[愿得一人] 2020-12-02 12:42

I am aware of the following post: Using Multiple Fragments in an single activity

What I am looking for is a specific answer to a specific problem. The result of the

相关标签:
1条回答
  • 2020-12-02 13:03

    Do the following:

    1. Change Fragment to FrameLayout in the main activity XML, for both.
    2. Change layout_width from fill_parent to match_parent, for both FrameLayout in the main XML file, (ones created in step 1).
    3. Change layout_height from fill_parent to wrap_content, for both FrameLayout in the main XML file, (ones created in step 1).
    4. Change FrameLayout to ListView in the List Fragment XML because it is a List.
    5. Change the id of this LisView to @android:id/list, because it is needed for the ListFragment.

    Then let me know, Cheers.

    Edit, also these:

    1. Change return inflater.inflate(R.layout.list_fragment, null); to return inflater.inflate(R.layout.list_fragment, container, false);.
    2. Change return inflater.inflate(R.layout.input_fragment, null); to return inflater.inflate(R.layout.input_fragment, container, false);

    Edit:

    Make your main activity XML file like this:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <FrameLayout
            android:id="@+id/message_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <FrameLayout
            android:id="@+id/send_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
    
    </RelativeLayout>
    

    I took out the android:name"..." because I don't know what that is nor able to find out what it is, if you know what it does for sure, just add it back, should be okay.

    0 讨论(0)
提交回复
热议问题