Android : Fragment doesn’t fit into Fragment Container
Posted By: Anonymous
I have a Fragment Container View inside MainActivity. And I have a register fragment. Inside the register fragment, I have Constraint layout.When I am starting app in my phone, register fragment doesn’t fit into Fragment Container. How can I solve this problem?
My MainActivity.xml code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_name"
android:textSize="64dp"
android:fontFamily="@font/roboto_medium"
android:textColor="@color/siyah"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/fragmentcontainerview_tasarimi"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:layout_margin="22dp"
app:navGraph="@navigation/nav_graph"
android:elevation="20dp"
android:stateListAnimator="@null"/>
</androidx.constraintlayout.widget.ConstraintLayout>
_x000D_
_x000D_
_x000D_
My Register Fragment xml code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RegisterEkrani"
android:background="@drawable/arkaplatform"
android:fitsSystemWindows="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/registerekrani_main_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:fontFamily="@font/roboto_medium"
android:text="Register"
android:textColor="@color/siyah"
android:textSize="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/registerekrani_isim_edittext"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:hint="İsmin"
android:textColorHint="@color/turuncu"
app:boxStrokeColor="@color/turuncu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_main_text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/registerekrani_username_edittext"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:hint="Kullanıcı Adın"
android:textColorHint="@color/turuncu"
app:boxStrokeColor="@color/turuncu"
app:helperTextTextColor="@color/siyah"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_isim_edittext">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/registerekrani_mail_edittext"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:hint="Mail adresin"
android:textColorHint="@color/turuncu"
app:boxStrokeColor="@color/turuncu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_username_edittext">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/registerekrani_sifren_edittext"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:hint="Åžifren"
android:textColorHint="@color/turuncu"
app:boxStrokeColor="@color/turuncu"
app:helperTextTextColor="@color/siyah"
app:endIconMode="password_toggle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_mail_edittext">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/register_button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@drawable/buton_tasarim"
android:elevation="10dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:stateListAnimator="@null"
android:text="Register"
android:layout_marginTop="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/register_iptal"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_sifren_edittext" />
<TextView
android:id="@+id/register_iptal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto_medium"
android:gravity="center"
android:letterSpacing="0.10"
android:padding="10dp"
android:text="Geri"
android:textColor="@color/siyah"
android:textSize="15dp"
android:layout_marginTop="45dp"
app:layout_constraintEnd_toStartOf="@id/register_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_sifren_edittext" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
_x000D_
_x000D_
_x000D_
Solution
The register Fragment fits perfectly fine, it is fitting according to the area available to it, in the Fragment Container. Since the area is limited, so that is why to you it seems it is being cut off.
Here is what you can do, you can add a ScrollView in your RegisterFragment, I have no idea why you are using a FrameLayout, but you would be fine replacing it with a ScrollView as far as I know. Beside that you will need to give bottom constraint to your last element and a margin from Bottom. Here is how it will be then.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RegisterEkrani"
android:background="@drawable/arkaplatform"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/registerekrani_main_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:fontFamily="@font/roboto_medium"
android:text="Register"
android:textColor="@color/siyah"
android:textSize="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/registerekrani_isim_edittext"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:hint="İsmin"
android:textColorHint="@color/turuncu"
app:boxStrokeColor="@color/turuncu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_main_text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/registerekrani_username_edittext"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:hint="Kullanıcı Adın"
android:textColorHint="@color/turuncu"
app:boxStrokeColor="@color/turuncu"
app:helperTextTextColor="@color/siyah"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_isim_edittext">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/registerekrani_mail_edittext"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:hint="Mail adresin"
android:textColorHint="@color/turuncu"
app:boxStrokeColor="@color/turuncu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_username_edittext">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/registerekrani_sifren_edittext"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:hint="Åžifren"
android:textColorHint="@color/turuncu"
app:boxStrokeColor="@color/turuncu"
app:helperTextTextColor="@color/siyah"
app:endIconMode="password_toggle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_mail_edittext">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/register_button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@drawable/buton_tasarim"
android:elevation="10dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:stateListAnimator="@null"
android:text="Register"
android:layout_marginTop="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/register_iptal"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_sifren_edittext" />
<TextView
android:id="@+id/register_iptal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto_medium"
android:gravity="center"
android:letterSpacing="0.10"
android:padding="10dp"
android:text="Geri"
android:textColor="@color/siyah"
android:textSize="15dp"
android:layout_marginTop="45dp"
android:layout_marginBottom="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/register_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerekrani_sifren_edittext" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Answered By: Anonymous
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.