当前位置: 动力学知识库 > 问答 > 编程问答 >

Android: TextInputLayout always leaves some space from top

问题描述:

I have this layout:

<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>

It looks like this:

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?

网友答案:

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"

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: