【发布时间】:2023-04-10 15:19:01
【问题描述】:
我目前正在使用 Material 组件创建一个 Android UI。 在我的活动中,我使用了 com.google.android.material.textfield.TextInputLayout-component 的错误功能。
问题在于,如果许多组件显示错误,则错误消息将无法正确显示。看起来消息在 material.textfield.TextInputEditText 后面,它是 TextInputLayout 的子项。请查看屏幕截图以进行说明。
有什么猜测吗?
<?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=".ui.createOffer.CreateOfferActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="6dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/offerImage"
android:layout_width="match_parent"
android:layout_height="230dp"
android:contentDescription="@string/postOffer_Image"
android:scaleType="centerInside"
app:layout_constraintBottom_toTopOf="@id/layout_Description"
app:layout_constraintTop_toBottomOf="@id/progressBar"
tools:srcCompat="@tools:sample/avatars" />
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:elevation="10dp"
android:indeterminate="true"
android:max="100"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/createOffer"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/component_label_horizontal_margin"
android:text="@string/postOffer_createOfferButton_Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_PurchaseDate" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_Price"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/postOffer_editTextPrice_hint"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@id/layout_Category"
app:layout_constraintTop_toBottomOf="@id/layout_Description">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="numberDecimal" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_Category"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:hint="@string/postOffer_Category"
android:inputType=""
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@id/layout_Price"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_ExpireDate">
<AutoCompleteTextView
android:id="@+id/filled_exposed_dropdown_ctagory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_ExpireDate"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:hint="@string/postOffer_ExpireDateHint"
android:inputType="none"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@id/layout_PurchaseDate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_Category">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText_expireDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAutofill="no"
android:inputType="date" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_PurchaseDate"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:hint="@string/postOffer_PurchaseDateHint"
android:inputType="none"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@id/createOffer"
app:layout_constraintTop_toBottomOf="@id/layout_ExpireDate">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText_purchaseDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:importantForAutofill="no"
android:inputType="date" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_Description"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/general_description"
android:inputType="textMultiLine"
android:maxLines="5"
app:counterEnabled="true"
app:counterMaxLength="255"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@id/layout_Price"
app:layout_constraintTop_toBottomOf="@id/offerImage">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/description_EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
问候:)
【问题讨论】:
-
为什么不添加一些边距/填充?
-
我已经尝试过使用边距和填充。但这不会解决问题。还有其他想法吗?
-
尝试垂直线性布局。或者,如果整个屏幕已满,布局可能会缩小。尝试将其包装在 ScrollView 中。如果两者都没有帮助,请发布整个 xml。
-
垂直线性布局没有解决问题。我将整个 xml 放入原始问题中,因为它对于答案字段来说太长了。
-
我的新答案有效吗?
标签: android android-layout material-design android-constraintlayout android-textinputlayout