简体   繁体   English

如何删除EditText drawable padding?

[英]How to remove EditText drawable padding?

I wasted the last hour trying to figure out how to get rid of this padding in a simple EditText: 我浪费了最后一小时试图弄清楚如何在一个简单的EditText中摆脱这个填充: 在此输入图像描述

All I want is to align the input with the rest of the content, just like the beautiful design guide says. 我想要的只是将输入与其他内容对齐,就像美丽的设计指南所说的那样。

The layout couldn't be simpler: 布局不可能更简单:

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

I tried setting padding on EditText to 0dp — the text shifted but the line remained as is. 我尝试将EditText上的填充设置为0dp - 文本已移位但行保持原样。 Strangely enough, I could not find ANY info on this issue, as if no one had noticed. 奇怪的是,我找不到关于这个问题的任何信息,好像没有人注意到。

I think the line is a background image for the EditText so changing the padding won't affect it. 我认为该行是EditText的背景图像,因此更改填充不会影响它。 If you want you can create a custom background drawable that has no padding. 如果需要,可以创建没有填充的自定义背景drawable。

Another hack you could do is add a negative margin to the 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"/>

Try giving "4dp" of padding for textView. 尝试为textView提供“4dp”的填充。 So that it matches with editText padding. 这样它就与editText填充匹配。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM