E
E
Egor2017-10-17 15:15:46
Java
Egor, 2017-10-17 15:15:46

How to make a fragment not take up the whole screen?

Here is the markup of the main activity in it a fragment and a bottom menu

<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:background="@color/backgroudMainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.egor.xcryptex.MainActivity">
    >

    <RelativeLayout
        android:id="@+id/contentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_navigation">
    </RelativeLayout>
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/backgroundLayoutMenu"
        app:itemIconTint="@drawable/collors_buttom_menu"
        app:itemTextColor="@color/white"
        app:menu="@menu/botton_menu_navigation"
        />
</RelativeLayout>

A fragment is embedded in the container, here is its markup; it has a black background:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black_color"
    tools:context="com.example.egor.xcryptex.fragments.FragmentPurse">
</RelativeLayout>

This is how I open
fragmentManager.beginTransaction().replace(R.id.container,fragmentPurse,TAG_4).commit()

Fragment Code:
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_fragment_purse, container, false);
    }

When opened, the fragment blocks all activity (and it becomes black as its background). It is necessary that it does not go beyond the scope of its container - "container" . Please help, I've been struggling with this for two days now

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Chvarkov, 2017-10-18
@EgorKurier

you specify the wrong id in
fragmentManager.beginTransaction().replace(R.id.container,fragmentPurse,TAG_4).commit()
you need
@+id/contentContainer

N
Neonoviiwolf, 2017-10-17
@Neonoviiwolf

the size of your container is "full screen", in the fragment you also specify "full screen" - everything works as you specified
android:layout_width="wrap_content" specify in the fragment and throw a TextView there, otherwise you will not see

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question