Android:TextInputLayout总是在顶部留有一些空间 [英] Android: TextInputLayout always leaves some space from top
问题描述
我有这样的布局:
<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 EditText
s 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屋!