gpt4 book ai didi

android-如何获得这样的边框

转载 作者:行者123 更新时间:2023-11-30 02:27:30 25 4
gpt4 key购买 nike

这是我想要的编辑文本:

enter image description here

这是我到目前为止得到的:

enter image description here

两个问题:

  1. 如您所见,顶部边框应该小得多。

  2. 我在代码中设置了填充,但如您所见,它不起作用。文本位于编辑文本的顶部。如何使其居中对齐并位于编辑文本的中间?

这是我的可绘制 xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="15dp"
android:shape="rectangle" >

<solid android:color="#3C1251" />

<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />

<stroke
android:width="2.3dp"
android:color="#56DEF1" />

</shape>

最佳答案

要减小顶部边框的大小,您可以尝试使用 inset 将整个可绘制对象向上移动一两个像素。

enter image description here

例如,对于 1dp 的顶部边框,您可以将描边宽度设置为 3,并将 insetTop 设置为 -2。

<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetTop="-2dp">

<shape
android:padding="15dp"
android:shape="rectangle" >

<solid android:color="#3C1251" />

<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />

<stroke
android:width="3dp"
android:color="#56DEF1" />
</shape>
</inset>

要将文本居中对齐,请尝试将 EditText 上的 android:gravity 设置为 center。要在边框边缘放置“填充”,请尝试设置 layout_margin

<EditText
...
android:background="@drawable/ourDrawable"
android:text="text goes here"
android:gravity="center"
android:layout_margin="5dp" />

关于android-如何获得这样的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27743461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com