Android:TextInputLayout总是在顶部留有一些空间 [英] Android: TextInputLayout always leaves some space from top

查看:131
本文介绍了Android:TextInputLayout总是在顶部留有一些空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的布局:

<LinearLayout
    android:id="@+id/dialogCentralContent"
    android:gravity="center_horizontal"
    android:layout_width="220dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/phoneNumberInfo"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="20dp"
    android:layout_centerHorizontal="true"
    android:orientation="horizontal"
    android:background="@drawable/edittext_white_rounded">

    <EditText
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:layout_weight="1"
        android:gravity="center"
        android:maxLines="1"
        android:inputType="none"
        android:focusable="false"
        android:text="@={dataContext.phonePrefix}"
        style="@style/Widget.App.PurchaseAmountEditText" />

    <android.support.design.widget.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        tools:errorEnabled="true"
        app:errorText="@{dataContext.validator.phoneValidation}">

        <android.support.design.widget.TextInputEditText
            android:layout_height="60dp"
            android:layout_width="match_parent"
            android:gravity="center"
            android:maxLines="1"
            android:inputType="phone"
            android:text="@={dataContext.phoneNumber}"
            style="@style/Widget.App.PurchaseAmountEditText" />

    </android.support.design.widget.TextInputLayout>

</LinearLayout>

它看起来像这样:

如您所见,第二个EditText呈现为低于第一个.当我在Android Studio的可视编辑器中查看它时,我可以看到TextInputLayout的顶部有一些可用空间,但是设置paddingTop="0dp"并没有任何改变.那么如何使这两个EditText呈现相同的方式?

As you can see the second EditText is rendered lower than the first one. When I look at it in the visual editor of Android Studio I can see that the TextInputLayout has some free space at its top, however setting paddingTop="0dp" didn't change anything. So how to make those two EditTexts render the same way?

推荐答案

默认情况下,TextInputLayout将在顶部保留浮动提示文本的空间.如果您不使用浮动提示,则可以通过在开始的<TextInputLayout>元素中添加以下内容来删除该空间.

By default, TextInputLayout will leave room at the top for the floating hint text. If you're not using the floating hint, you can remove that space by adding the following to the opening <TextInputLayout> element.

app:hintEnabled="false"

常规提示文本为空时在TextInputEditText上仍然可见.

The regular hint text will still be visible on the TextInputEditText when it's empty.

这篇关于Android:TextInputLayout总是在顶部留有一些空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆