0

I am a beginner in android so I might be missing something simple but I have a "strange problem". I have two fragments and I can display them successfully when I want to display them on their own. Now I want to display them side by side and I wrote the following but it only displays the second fragment. (frag2)

Here is the xml in my activity

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <fragment class="com.example.frag1"
        android:id="@+id/fragone"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <fragment class="com.example.frag2"
        android:id="@+id/fragtwo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

Here is the activity I use

  @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout_activity_main);
}
John Joe
  • 12,412
  • 16
  • 70
  • 135
Freshia
  • 17
  • 4
  • You have both of their `layout_width`s set to `match_parent`, so one of them is pushed out the side of the `LinearLayout`. – Mike M. Apr 01 '17 at 03:18
  • What is the correct way to fix it? Should I assign weights? – Freshia Apr 01 '17 at 03:19
  • That's an option. If you want them both the same width, set their `layout_width`s to `0dp`, and their `layout_weight`s to `1`. – Mike M. Apr 01 '17 at 03:21
  • Actually, this has been covered several times here already, so I'll just close it as a duplicate of a similar question. Thanks, though. Glad it worked for ya. Cheers! – Mike M. Apr 01 '17 at 03:30

0 Answers0