Android : 片段不适合片段容器

Android : Fragment doesn't fit into Fragment Container

我在 MainActivity 中有一个 Fragment Container View。我有一个寄存器片段。在寄存器片段中,我有约束 layout.When 我正在 phone 中启动应用程序,寄存器片段不适合片段容器。我该如何解决这个问题?


ScreenShoot from my app


我的MainActivity.xml代码

<?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>

我的注册片段xml代码

<?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>

register Fragment 非常适合,它根据 Fragment Container 中可用的区域进行调整。由于面积有限,所以在你看来好像是被切断了。

这是你可以做的,你可以在你的 RegisterFragment 中添加一个 ScrollView,我不知道你为什么要使用 FrameLayout,但据我所知,你可以用 ScrollView 替换它。除此之外,您还需要为最后一个元素提供底部约束,并从底部留出边距。到时候会是这样。

<?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>