Search code examples
androidandroid-layoutandroid-fragmentsandroid-constraintlayout

Why is it a single fragment is taking the whole screen in an activity with other views that usesconstraint layout?


there are two framelayouts in my main activity which will be replaced by two fragments during run time. I am using constraint layout to align them . One particular fragment that occupies a framelayout with id recentsfragment is replacing the whole screen and giving no place to other framelayout .

when i individually display the framelayouts with their fragments,the view is exactly as expected .

activity_main.xml

<layout 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"
>
 <androidx.constraintlayout.widget.ConstraintLayout


  android:layout_width="match_parent"
  android:layout_height="match_parent">

<FrameLayout
    android:id="@+id/recentsfragment"
    android:layout_width="395dp"
    android:layout_height="325dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.618"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/view"></FrameLayout>

<view
    android:id="@+id/view"
    class="android.widget.Button"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_marginBottom="8dp"
    android:background="@android:color/darker_gray"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:layout_editor_absoluteX="-51dp" />

<FrameLayout
    android:id="@+id/allnotesfragment"
    android:layout_width="395dp"
    android:layout_height="327dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toTopOf="@+id/view"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"></FrameLayout>

I have tried different alignments for them with no luck. I want to use constraint layout in particular. any help is appreciated .Thank you.


Solution

  • The issue is not really because of the layouts but because in one of the fragments above I used data binding inappropriately and that occupied the whole screen of the app leaving no space for other fragment . Thank you