S
S
SerGio13132017-02-08 19:01:23
Android
SerGio1313, 2017-02-08 19:01:23

How to make a fragment full screen?

Performing a transaction in the activity code to replace the entire current screen with a fragment - nothing happens. Components (buttons) remain in place, and the fragment takes the remaining space. How to make fragments full screen?

Fragment fragment = new SettingsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

<?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="vertical" >
  <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="button1"
        android:onClick="selectFrag" />
     <Button
         android:id="@+id/button2"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:onClick="selectFrag"
         android:text="button2" />
   <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</LinearLayout>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2017-02-08
@niku_andrew

It is written in your layout that the fragment would be "inserted" after the buttons, in the FrameLayout. What would be on the whole screen, you can create a layout with one root FrameLayout.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question