TextInputEditText,如何将提示与上边距对齐

aer*_*xr1 3 android android-layout android-textinputlayout android-textinputedittext material-components-android

如果我使用最新的材质库版本com.google.android.material:material:1.2.0-alpha02,我在 TextInputEditText 和他的提示消息方面遇到了一些麻烦。我设置了 5 行可滚动 textInputEditText 并且我想显示提示消息与该文本输入的上边距对齐。在布局编辑器上出现在正确的位置,但是当我运行应用程序时,位置是垂直居中的。为什么 ?

相反,我没有遇到这个问题com.google.android.material:material:1.1.0-beta02

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:id="@+id/sendMailContainer"
    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="wrap_content">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/popupTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:layout_marginTop="20dp"
            android:text="@string/sendBusinessCard"
            android:textColor="@android:color/black"
            android:textSize="22sp" />

        <TextView
            android:id="@+id/subTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/sendBusinessCard"
            android:textColor="@android:color/black"
            android:textSize="18sp"
            android:layout_below="@+id/popupTitle"
            android:layout_marginEnd="40dp"
            android:layout_marginStart="40dp"
            android:layout_marginTop="20dp"/>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/noteMessageContainer"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/subTitle"
            android:layout_marginEnd="40dp"
            android:layout_marginStart="40dp"
            android:layout_marginTop="10dp">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/noteMessage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/emailText"
                android:inputType="text|textMultiLine|textCapSentences"
                android:textColor="@android:color/black"
                android:textColorHint="@color/gray9B"
                android:textSize="16sp"
                android:isScrollContainer="true"
                android:scrollbars="vertical"
                android:textIsSelectable="true"
                android:minLines="5"
                android:maxLines="5"
                android:gravity="top"/>

        </com.google.android.material.textfield.TextInputLayout>

        <Button
            android:id="@+id/notePopupLeftButton"
            android:layout_width="180dp"
            android:layout_height="35dp"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/noteMessageContainer"
            android:layout_marginBottom="20dp"
            android:layout_marginStart="20dp"
            android:layout_marginTop="40dp"
            android:background="#FF515151"
            android:text="@string/Cancel"
            android:textAllCaps="true"
            android:textColor="@android:color/white"
            android:textSize="16sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/notePopupRightButton"
            android:layout_width="180dp"
            android:layout_height="35dp"
            android:layout_alignParentEnd="true"
            android:layout_below="@+id/noteMessageContainer"
            android:layout_marginBottom="20dp"
            android:layout_marginEnd="20dp"
            android:layout_marginTop="40dp"
            android:background="#FF515151"
            android:text="@string/Send"
            android:textAllCaps="true"
            android:textColor="@android:color/white"
            android:textSize="16sp"
            android:textStyle="bold" />

    </RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

这是两个屏幕截图,一个是在正确位置提示的布局编辑器,另一个是应用程序屏幕截图:

在此处输入图片说明 在此处输入图片说明 在此处输入代码

小智 11

您可以使用

android:gravity="top|start" 
Run Code Online (Sandbox Code Playgroud)

地址块的 EditText 中的属性,它将充当容器的底层控制属性,并将提示带到左上角。