Android忽略了EditText中的填充

时间:2021-01-22 20:15:50

could somebody tell my why Android is ignoring padding i added? Have i did something terribly stupid? I was trying to make some custom inputs for texts. But i encountered weird problem with padding inside EditTexts

有人可以告诉我为什么Android会忽略我添加的填充吗?我做了一件非常愚蠢的事吗?我试图为文本做一些自定义输入。但我在EditTexts中遇到了填充的奇怪问题

Android忽略了EditText中的填充

Code:

<RelativeLayout 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:background="@color/lightBeige"
    tools:context=".LoginActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:background="@color/lightBrown"
            android:layout_height="0dp"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.53"
            android:contentDescription="@string/app_logo"
            android:src="@drawable/logo"
            android:paddingLeft="20dp"
            android:paddingRight="20dp" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="10dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp">

            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:capitalize="characters"
                android:text="@string/login_text"
                android:textSize="40dp"
                android:background="@color/semiGold"
                android:textStyle="bold"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:layout_marginBottom="20dp"
                android:layout_marginTop="20dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/greyBeige"
                android:orientation="vertical"
                android:padding="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp">

                <EditText
                    android:id="@+id/login_name"
                    android:background="@drawable/edit_text_cronline"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:inputType="text"
                    android:hint="@string/input_login_text"
                    android:paddingTop="15dp"
                    android:paddingBottom="15dp"
                    android:paddingLeft="10dp"
                    android:layout_marginBottom="5dp"
                    android:paddingRight="10dp" />
                <EditText
                    android:id="@+id/login_pass"
                    android:background="@drawable/edit_text_cronline"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:inputType="text"
                    android:hint="@string/input_password_text"
                    android:paddingTop="15dp"
                    android:paddingBottom="15dp"
                    android:paddingLeft="10dp"
                    android:layout_marginBottom="5dp"
                    android:paddingRight="10dp" />

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/button_login_text"
                    android:id="@+id/loginButton"
                    android:background="@drawable/button_cronline"/>

            </LinearLayout>
        </LinearLayout>

    </LinearLayout>
</RelativeLayout>

And my custom thingy for inputs:

我输入的定制东西:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- main color -->
    <item
        android:bottom="4dp"
        android:left="1.5dp"
        android:right="1.5dp">
        <shape>
            <solid android:color="#FEFEFE" />
        </shape>
    </item>

    <!-- draw another block to cut-off the left and right bars -->
    <item android:bottom="5.0dp">
        <shape>
            <solid android:color="#FEFEFE" />
        </shape>
    </item>

</layer-list>

1 个解决方案

#1


You should add padding to your items in edit_text_cronline.xml instead of EditText.

您应该在edit_text_cronline.xml而不是EditText中为项目添加填充。

#1


You should add padding to your items in edit_text_cronline.xml instead of EditText.

您应该在edit_text_cronline.xml而不是EditText中为项目添加填充。