gpt4 book ai didi

android - 如何将兄弟 View 限制为与 TextInputLayout 的 TextInputEditText 相同的高度

转载 作者:行者123 更新时间:2023-11-30 05:01:40 28 4
gpt4 key购买 nike

我想显示带有白色背景的标签“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”标签垂直对齐到同一水平。

最佳答案

As I understand your question check below answer

Give kmLable top and bottom constraint to edit text. Here I give fix width for a temporary purpose (change according to your requirement).

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>

关于android - 如何将兄弟 View 限制为与 TextInputLayout 的 TextInputEditText 相同的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58143911/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com