简体   繁体   English

DrawableRight 到 EditText 或 Button 的右端

[英]DrawableRight to right end of EditText or Button

I want my drawableRight at the end of my edit text.我希望我的drawableRight位于编辑文本的末尾。

在此处输入图像描述

As you can see in the picture it is not at the end.正如您在图片中看到的那样,它还没有结束。

Code of my EditText:我的 EditText 代码:

<EditText
    android:id="@+id/btnDB"
    android:layout_width="300dp"
    android:layout_height="52dp"
    android:layout_marginTop="20dp"
    android:background="@drawable/textfield2r"
    android:layout_gravity="center"
    android:drawableRight="@drawable/db_ic"
    android:ems="10"
    android:text="Daten einsehen"
    android:textAlignment="viewEnd"
    android:paddingLeft="5dp"
    android:paddingTop="5dp"
    android:paddingEnd="5dp"
    android:paddingRight="5dp"
    android:textColor="#000000"
    android:textColorHint="#7A7A7A"
    android:textSize="18dp"
    tools:ignore="RtlCompat" />

And here the xml of the background:这里是背景的xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#EBEBEB"/>
    <stroke
        android:width="1dp"
        android:color="#D30F1D"/>
    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp"/>
    <corners
        android:bottomLeftRadius="30dp"
        android:bottomRightRadius="30dp"
        android:topLeftRadius="30dp"
        android:topRightRadius="30dp"/>
</shape>

At the end it should look like this:最后它应该是这样的: 在此处输入图像描述

Thanks for helping me, kind regards, Jeremy谢谢你帮助我,亲切的问候,杰里米

You need to set the end padding to 0dp instead of 5dp您需要将结束填充设置为0dp而不是5dp

Or ideally you can set it to 1dp as the stroke of the background is 1dp或者理想情况下,您可以将其设置为1dp ,因为背景的描边是1dp

Also set the paddingTop to 1dp to make the stroke frame appear at the bottom同时将paddingTop设置为 1dp 使笔划框出现在底部

<EditText
    .....
    android:paddingTop="1dp"
    android:paddingEnd="1dp"
    android:paddingRight="1dp"

Test:测试:

在此处输入图像描述

Finally i was able to fix it.最后我能够修复它。

I made a RTL linear layout in which i put in my EditText:我制作了一个 RTL 线性布局,其中我放入了我的 EditText:

<LinearLayout
                android:layout_width="match_parent"
                android:layoutDirection="rtl"
                android:layout_height="match_parent"
                android:layout_weight="1.0"
                android:background="#00FFFFFF"
                android:orientation="vertical">

                <EditText
                    android:id="@+id/btnData"
                    android:layout_width="300dp"
                    android:layout_height="52dp"
                    android:layout_marginTop="20dp"
                    android:gravity="center_vertical|right"
                    android:background="@drawable/textfield2r"
                    android:layout_gravity="center"
                    android:drawableRight="@drawable/console"
                    android:ems="10"
                    android:text="Daten einsehen"
                    android:paddingLeft="5dp"
                    android:paddingTop="5dp"
                    android:paddingEnd="5dp"
                    android:paddingRight="5dp"
                    android:textColor="#000000"
                    android:textColorHint="#7A7A7A"
                    android:textSize="18dp" />

            </LinearLayout>

Then I changed the xml of my button background:然后我更改了按钮背景的 xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#EBEBEB"/>
<stroke
    android:width="1dp"
    android:color="#D30F1D"/>
<padding
    android:bottom="-1dp"
    android:left="0dp"
    android:right="-8dp"
    android:top="0dp"/>
<corners
    android:bottomLeftRadius="30dp"
    android:bottomRightRadius="30dp"
    android:topLeftRadius="30dp"
    android:topRightRadius="30dp"/>

Now everything is like i wanted it.现在一切都像我想要的那样。

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

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