代码之家  ›  专栏  ›  技术社区  ›  M.kazem Akhgary

如何在textinputlayout上设置maxheight

  •  0
  • M.kazem Akhgary  · 技术社区  · 7 年前

    我不想限制行数,我想限制 TextInputLayout 最大高度,如果它太长,它会垂直滚动。

    我对代码内解决方案很在行。

    目前 maxHeight 属性对 文本输入布局 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,将使布局固定高度(不是由 布局限制最大 但固定的默认编辑文本高度)

    1 回复  |  直到 7 年前
        1
  •  0
  •   Aaron    7 年前

    layout_constraintHeight_max 如果视图没有顶部或底部约束,则不起作用,因此您可以将 android:maxHeight InputEditText ,或调整 TextInputLayout 以下内容:

    <include
            layout="@layout/view_text_input_layout_address"
            android:id="@+id/text_input_layout_address"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHeight_default="wrap"
            app:layout_constraintHeight_max="200dp" />
    

    你可能只需要 app:layout_constraintHeight_default="wrap" 如果父对象的高度为 match_parent 是的。