Android 如何删除EditText可绘制填充?
我浪费了最后一个小时试图找出如何在一个简单的编辑文本中消除这种填充: 我所要做的就是将输入与其余内容对齐,就像beautiful所说的那样 布局再简单不过了:Android 如何删除EditText可绘制填充?,android,android-layout,android-edittext,Android,Android Layout,Android Edittext,我浪费了最后一个小时试图找出如何在一个简单的编辑文本中消除这种填充: 我所要做的就是将输入与其余内容对齐,就像beautiful所说的那样 布局再简单不过了: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="ma
<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-文本移动了,但行保持原样。奇怪的是,我找不到关于这个问题的任何信息,好像没有人注意到。
<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>
尝试为textView提供“4dp”的填充。使其与editText填充匹配 我认为该行是EditText的背景图像,因此更改填充不会影响它。如果需要,可以创建一个没有填充的自定义背景绘图
你可以做的另一个技巧是在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"/>
鉴于您的解决方案增加了布局的深度/复杂性,您能否解释一下为什么您所做的更改能够解决问题。我考虑过这一点。我不完全确定这个解决方案是否会破坏棒棒糖前的用户界面(我最不希望的是有很多特定于版本的XML),我同意你的看法。但这只是一个小小的工作。我用4.4.2和5.0检查了在我的设备中添加填充和Emulator的结果,它似乎工作得很好。似乎开发人员只是考虑了过多的4dp,使得利润率变小了。天哪……P.S。有些东西告诉我,就像Android中的其他任何东西一样,即使是这件小事,我也必须制作自己的绘图工具。。。我只是想知道为什么他们的原生小部件不遵循他们自己的设计规范…查看联系人应用程序。谷歌开发人员似乎遵循了这条道路,只是解释了过度的4次下跌。我真的认为会有更好的解决办法。在合适的情况下,他们就这样离开了是的,我同意,应该有更好的方法来做到这一点。完美主义很糟糕:)现在我担心当他们推出一种新的设计语言时,这会打破:)应该有一些适当的方法来处理它,他们可能会在编辑文本中保留一个属性吗