Как ограничить одноуровневое представление той же высотой, что и TextInputEditText TextInputLayout - PullRequest
1 голос
/ 28 сентября 2019

Я хочу показать метку «Km» на белом фоне с такой же высотой, как у текстового поля редактирования.

   <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">


            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/textInputLayoutInputDist"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                android:layout_width="wrap_content"
                android:layout_height="42dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/inputDist"
                    android:layout_width="80dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/bg_left_corner_shape"
                    android:backgroundTint="@android:color/white"
                    android:fontFamily="@font/roboto_regular"
                    android:imeOptions="actionDone"
                    android:inputType="numberDecimal"
                    android:maxEms="4"
                    android:padding="4dp"
                    android:textColor="@color/colorPrimaryDark"
                    android:textSize="14sp" />
            </com.google.android.material.textfield.TextInputLayout>


            <TextView
                android:id="@+id/label_km"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_marginTop="4dp"
                android:background="@drawable/bg_right_corner_shape"
                android:backgroundTint="@android:color/white"
                android:fontFamily="@font/roboto_regular"
                android:gravity="center_vertical"
                android:text="@string/km"
                android:textColor="@color/colorPrimaryDark"
                android:textSize="14sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/textInputLayoutInputDist"
                app:layout_constraintTop_toTopOf="@+id/textInputLayoutInputDist" />
        </androidx.constraintlayout.widget.ConstraintLayout>

Но TextInputLayout занимает немного больше высоты, чем текстовое поле редактированияЯ не могу выровнять текст редактирования и метку «Km» по вертикали одинаковых уровней.

1 Ответ

0 голосов
/ 28 сентября 2019

Насколько я понимаю ваш вопрос, проверьте ответ ниже

Дайте kmLable ограничение сверху и снизу для редактирования текста.Здесь я даю фиксированную ширину для временного назначения (изменяйте в соответствии с вашими требованиями).

enter image description here

    <?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:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayoutInputDist"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/inputDist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/dividerColor"
            android:fontFamily="@font/roboto_bold"
            android:imeOptions="actionDone"
            android:inputType="numberDecimal"
            android:maxEms="4"
            android:padding="4dp"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="14sp" />
    </com.google.android.material.textfield.TextInputLayout>

    <TextView
        android:id="@+id/label_km"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:background="@color/dividerColor"
        android:fontFamily="@font/roboto_medium"
        android:gravity="center_vertical"
        android:text="km"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="14sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="@+id/textInputLayoutInputDist"
        app:layout_constraintStart_toEndOf="@+id/textInputLayoutInputDist"
        app:layout_constraintTop_toTopOf="@+id/textInputLayoutInputDist" />

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