默认的 EditText 背景似乎在左侧放置了 ~ 4dp 的填充。这会导致与其他小部件不对齐。
我做了一个简单的应用来演示。截图:
布局:
<LinearLayout 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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:background="#00ff00"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="HINT"
android:text="TEXT"
android:singleLine="true"/>
<TextView
android:background="#00ff00"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
有没有办法阻止它这样做?
最佳答案
一种解决方法是在两侧使用负边距 (-4dp)
这仅在 EditText 背景与 Layout 背景匹配时有效,并且您在 Layout 的两侧没有任何东西会被 EditText 覆盖
关于android - 删除 Android EditText 上的左侧填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31735291/