我不想限制行数,而是希望限制TextInputLayout
的最大高度,以便如果它太长,就会变成垂直滚动。
我可以接受在代码中解决这个问题。
目前maxHeight
属性对TextInputLayout
或EditText
都没有影响。
这是我的布局:
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="0dp"
android:layout_height="0dp"
android:hint="@string/address"
android:paddingTop="@dimen/margin_8"
android:paddingBottom="@dimen/margin_8">
<com.mamamia.mamamiarestaurant.ui.MultiLineTextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionNext"
android:inputType="text|textPostalAddress|textMultiLine"
android:maxLength="@integer/address_max_length" />
</com.google.android.material.textfield.TextInputLayout>
我将其包含在一个约束布局中
<include
android:id="@+id/text_input_layout_address"
layout="@layout/view_text_input_layout_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintHeight_max="200dp" />
layout_constraintHeight_max
没有效果。但是,如果将layout_constrainedHeight
设置为true,则会使布局的高度固定(不是由layout_constraintHeight_max
指定的高度,而是默认的固定编辑文本高度)。