如何去除EditText中的Drawable填充?

8

我浪费了最后一个小时试图弄清楚如何消除简单EditText中的填充:

enter image description here

我想要的只是将输入与其余内容对齐,就像美丽的设计指南所说的那样。

布局不能再简单了:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.actinarium.tiomantas.SetupChallengeFragment">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:orientation="vertical">

        <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/new_challenge_name"/>

        <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="@string/new_challenge_name_hint1"
                android:singleLine="false"/>

    </LinearLayout>

</ScrollView>

我尝试将EditText的padding设置为0dp-文本会移动,但是行仍然保持不变。很奇怪,我找不到任何关于这个问题的信息,好像没有人注意到。


PS:有些东西告诉我,就像 Android 中的任何其他事物一样,即使对于这种微不足道的事情,我也必须制作自己的可绘制对象... 我只是想知道为什么他们的本地小部件不遵循自己的设计规范... - Actine
3个回答

8
我认为这条线是EditText的背景图像,所以改变填充不会影响它。如果您想要,可以创建一个没有填充的自定义背景drawable。
另一个可行的方法是向EditText添加负边距:
        <EditText
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginLeft="-4dp"
             android:hint="@string/new_challenge_name_hint1"
             android:singleLine="false"/>

1
看了一下联系人应用程序。似乎谷歌开发人员遵循了这条路线,并考虑到了过多的4个dip。我真的以为会有更好的解决方案。 而在Fit中,他们只是保持原样。 - Actine
是的,我同意,应该有更好的方法来做这件事。 - l-l
追求完美真是太糟糕了 :) 现在我担心当他们推出新的设计语言时,这可能会出问题 :) - Actine
应该有一种适当的方式来处理它,也许他们在EditText中保留了一个属性。 - sonal balekai

1
尝试为textView提供“4dp”的填充,以使其与editText的填充相匹配。

我考虑过这个问题。但我并不完全确定这种解决方法是否会破坏在Lollipop之前的用户界面(我最不想要的就是有很多版本特定的XML文件)。 - Actine
我同意你的看法。但这只是一个小的解决方法。我在我的设备上添加了填充后检查了结果,包括4.4.2版本和5.0版本的模拟器,看起来都正常工作。 - Quantum_VC
刚刚查看了Lollipop上的联系人应用程序。看起来开发人员只是考虑到了那个过多的4dp并缩小了边距。哎呀... - Actine

-1
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.actinarium.tiomantas.SetupChallengeFragment">
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="jhjkhkhkjkljlkjkljlkj"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:hint="hjhjhjkhjkhjkhkjhoiuyiyirehyiohj"
            android:singleLine="false"/>
    </LinearLayout>
</LinearLayout>
</ScrollView>

你能否解释一下,为什么你所做的更改会解决问题 - 考虑到你的解决方案会增加布局深度/复杂性。 - Vikram

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接