Мой фрагмент не заполняет весь экран - PullRequest
0 голосов
/ 05 марта 2020

Я создал подписку и подписал фрагмент, но на больших экранах он не заполняет экран, а на маленьких экранах он выдвигается.

Вот изображения о том, как это выглядит в целом и маленькие экраны.

Структура каталогов моей папки res.

enter image description here

большой экран:

enter image description here

маленький экран:

enter image description here

Ниже приведен файл xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".SignInFragment"
    android:background="@color/colorPrimaryDark">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageButton
            .../>

        <ImageView
            ... />

        <EditText
            ... />

        <EditText
            ... />

        <TextView
            ... />

        <Button
            .... />

        <TextView
            .../>

        <TextView
            ... />

        <View
            ... />

        <View
            ..."/>


    </androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>

1 Ответ

0 голосов
/ 05 марта 2020

Попробуйте этот код:

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/colorPrimaryDark">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:gravity="center">

        <ImageButton
            android:id="@+id/btn_close"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:padding="16dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.25" />

        <EditText
            android:id="@+id/Sign_In_Email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="30dp"
            android:layout_marginTop="20dp"
            android:layout_marginEnd="30dp"
            android:ems="10"
            android:hint="Your Email"
            android:textColor="@color/cardview_light_background"
            android:inputType="textEmailAddress"
            android:textColorHint="@color/colorAccent"
            android:backgroundTint="@color/colorAccent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/imageView" />

        <EditText
            android:id="@+id/Sign_In_Password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="30dp"
            android:layout_marginEnd="30dp"
            android:ems="10"
            android:hint="Your Password"
            android:textColor="@color/cardview_light_background"
            android:textColorHint="@color/colorAccent"
            android:backgroundTint="@color/colorAccent"
            android:inputType="textPassword"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/Sign_In_Email"
            app:layout_constraintVertical_bias="0.050000012" />

        <TextView
            android:id="@+id/Sign_In_ForgotPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="33dp"
            android:layout_marginTop="5dp"
            android:text="Forgot Password?"
            android:textColor="@color/cardview_light_background"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/Sign_In_Password"
            android:layout_marginLeft="33dp" />

        <Button
            android:id="@+id/btn_SignIn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="30dp"
            android:layout_marginEnd="30dp"
            android:text="Sign In"
            android:textSize="15dp"
            android:textAllCaps="false"
            android:textColor="@color/cardview_light_background"
            android:background="@color/colorAccent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/Sign_In_ForgotPassword" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="28dp"
            android:text="or"
            android:textColor="@color/cardview_light_background"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/btn_SignIn" />

        <TextView
            android:id="@+id/dont_have_Account"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Don't have an Account? Sign Up!"
            android:textColor="@color/cardview_light_background"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.497"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView2" />

        <View
            android:id="@+id/divider"
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_marginEnd="10dp"
            android:background="@color/cardview_dark_background"
            app:layout_constraintBottom_toTopOf="@+id/dont_have_Account"
            app:layout_constraintEnd_toStartOf="@+id/textView2"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/btn_SignIn"
            android:layout_marginRight="10dp" />

        <View
            android:id="@+id/divider2"
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_marginStart="10dp"
            android:background="@color/cardview_dark_background"
            app:layout_constraintBottom_toTopOf="@+id/dont_have_Account"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@+id/textView2"
            app:layout_constraintTop_toBottomOf="@+id/btn_SignIn"
            android:layout_marginLeft="10dp" />
        </LinearLayout>/


    </androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>

Вы должны поместить элементы в линейное расположение и установить его гравитацию в «центр». Это будет выводиться на разных экранах:

enter image description here

...