О высоте макета ограничения - PullRequest
0 голосов
/ 23 апреля 2020

На следующем рисунке показан вывод, который я хотел сделать:

enter image description here

Я уже прошел

Как установить родителя соответствия высоты представления в ConstraintLayout?

и

https://developer.android.com/reference/android/support/constraint/ConstraintLayout

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

А также прямоугольные angular верхние изогнутые углы, один находится на заднем плане макет ограничения. Теперь я не получаю высоту этого макета ограничения, нижняя часть которого должна касаться нижней части экрана, но как только я объявляю высоту родительским соответствием, она занимает весь экран сверху вниз. Ниже приведен мой XML код.

     <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"
android:background="@color/silver"
tools:context=".ResetPassword">


<RelativeLayout
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_marginLeft="20dp"
    android:layout_marginStart="20dp"
    android:layout_marginTop="20dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@drawable/circle_shape"
    >
    <ImageView
        android:id="@+id/iv_reset_bck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_arrow_back_black_24dp"></ImageView>

</RelativeLayout>


<RelativeLayout
    android:id="@+id/rl_reset_topImage"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_marginTop="40dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@drawable/circle_shape">
    <ImageView
        android:id="@+id/iv_reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="20dp"
        app:srcCompat="@mipmap/ic_launcher_round" />
</RelativeLayout>
    <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:background="@drawable/bg_rectangle"
    android:paddingLeft="5dp"
    android:paddingTop="5dp"
    android:paddingRight="5dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/rl_reset_topImage">

    <LinearLayout
        android:id="@+id/welcomeLoginLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteY="5dp">

        <com.example.portfolio.CustomViews.PopinsBoldTextView
            android:id="@+id/tv_welcome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="43dp"
            android:layout_marginLeft="43dp"
            android:layout_marginTop="44dp"
            android:text="@string/welcome"
            android:textColor="@color/black"
            android:textSize="26sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <com.example.portfolio.CustomViews.PopinsBoldTextView
            android:id="@+id/tv_logintext_msg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="43dp"
            android:layout_marginLeft="43dp"
            android:text="@string/loginwith"
            android:textColor="@color/black"
            android:textSize="20sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/emailRelativeLayout"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginStart="40dp"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="40dp"
        android:layout_marginRight="40dp"
        android:background="@drawable/bg_email_rect"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/welcomeLoginLayout">

        <EditText
            android:id="@+id/et_email"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginEnd="20dp"
            android:layout_marginRight="20dp"
            android:background="@android:color/transparent"
            android:hint="@string/prompt_email"
            android:paddingTop="5dp"
            android:textSize="20sp"
            android:paddingBottom="5dp"
            android:textColorHint="@color/dark_gey"></EditText>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/passwordlRelativeLayout"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginStart="40dp"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="40dp"
        android:layout_marginRight="40dp"
        android:background="@drawable/bg_email_rect"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/emailRelativeLayout">

        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginEnd="20dp"
            android:layout_marginRight="20dp"
            android:background="@android:color/transparent"
            android:hint="@string/prompt_password"
            android:textSize="20sp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:textColorHint="@color/dark_gey"></EditText>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/login_btnLayout"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginStart="40dp"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="40dp"
        android:layout_marginRight="40dp"
        android:background="@drawable/bg_btn"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/passwordlRelativeLayout">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Login"
            android:textColor="#FFF"
            android:textSize="20dp"
            android:textStyle="bold"></TextView>
    </RelativeLayout>
 </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Это то, что я получаю из вышеприведенного кода

enter image description here

Как я могу сделать это как на картинке выше?

1 Ответ

1 голос
/ 23 апреля 2020

Как уже упоминалось в комментарии, вам не нужно настраивать родительские макеты внутри ConstraintLayout, так как ConstraintLayout довольно мощный и может легко достичь того, что вы хотите. Вам не хватает хорошего использования constraints, и вы пытаетесь компенсировать это, используя RelativeLayout. Наличие ConstraintLayout внутри ConstraintLayout является излишним.

Я не создал BottomSheet для вас ResetPassword, но это то, что вы можете работать над собой, просто упорядочивая элементы или внося customView. Моя точка зрения состоит в том, чтобы просто использовать один ConstraintLayout в качестве родителя, который будет управлять всеми ViewGroups, и воздерживаться от использования любых других Layouts внутри it.

Предварительный просмотр дизайна

image

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

  <ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    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"
    tools:srcCompat="@tools:sample/avatars" />

  <TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="100dp"
    android:text="Reset your password"
    app:layout_constraintEnd_toEndOf="@+id/imageView2"
    app:layout_constraintStart_toStartOf="@+id/imageView2"
    app:layout_constraintTop_toBottomOf="@+id/imageView2" />

  <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:text="Reset your password to use app"
    app:layout_constraintEnd_toEndOf="@+id/textView"
    app:layout_constraintStart_toStartOf="@+id/textView"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

  <EditText
    android:id="@+id/editTextTextPersonName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="100dp"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Name"
    app:layout_constraintEnd_toEndOf="@+id/textView2"
    app:layout_constraintStart_toStartOf="@+id/textView2"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />

  <EditText
    android:id="@+id/editTextTextPassword"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Password"
    android:inputType="textPassword"
    app:layout_constraintEnd_toEndOf="@+id/editTextTextPersonName"
    app:layout_constraintStart_toStartOf="@+id/editTextTextPersonName"
    app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName" />

  <Button
    android:id="@+id/button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Button"
    app:layout_constraintEnd_toEndOf="@+id/editTextTextPassword"
    app:layout_constraintStart_toStartOf="@+id/editTextTextPassword"
    app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword" />

</androidx.constraintlayout.widget.ConstraintLayout>
...