You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TextInputLayout中Hint与startIconDrawable重叠问题求助

TextInputLayout提示文本与起始图标重叠问题解决

你的问题出在两个关键属性的设置上,直接修改即可解决:

  1. 移除app:boxCollapsedPaddingTop="25dp"
    这个属性会强制将折叠状态下的提示文本向下偏移,直接导致它和左侧的startIcon重叠。Material Design组件默认会自动处理提示文本与图标的间距,无需手动添加这个内边距。

  2. 替换固定高度android:layout_height="60dp"为wrap_content
    固定高度会压缩TextInputLayout的内部空间,让提示文本和图标没有足够的空间分隔。使用wrap_content可以让控件根据内部元素自适应高度,保证布局正常。

修改后的完整XML代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:orientation="vertical"
    tools:context=".SignUp">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sign Up"
        android:textStyle="bold"
        android:textSize="25sp"
        android:layout_margin="20dp" />

    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:boxBackgroundColor="@color/white"
        app:startIconDrawable="@drawable/baseline_person_24"
        android:layout_marginStart="30dp"
        android:layout_marginEnd="30dp">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Name" />
    </com.google.android.material.textfield.TextInputLayout>

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="Button" />

</LinearLayout>

另外补充:textSize建议用sp单位而非dp,这样会跟随系统字体大小变化,提升界面的可访问性。

内容的提问来源于stack exchange,提问作者Yaseen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 08:32:13