gpt4 book ai didi

android - 布局的圆形矩形边框

转载 作者:IT王子 更新时间:2023-10-28 23:28:49 25 4
gpt4 key购买 nike

在我的应用程序中,我将使用很多布局“边框”,它们是一个简单的圆角矩形。为了测试它的外观,我创建了一个具有透明背景的 .png 文件:

enter image description here

我只是将图像设置为我的布局背景。问题是我需要为其他布局使用不同的比例,而在 Photoshop 中为我的所有布局创建这样的图像会浪费时间。

问题:我怎样才能使用 android API(可能是 XML 形状)做同样的事情,但允许矩形被拉伸(stretch)到任何尺寸并且仍然保持锐利?

最佳答案

你可以使用drawable

在drawable文件夹中有bkg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke
android:width="3dp"
android:color="#0FECFF"/>
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp"/>
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>

然后设置背景

  android:background="@drawable/bkg" //to required view

将可绘制背景设置为 textview 时图形编辑器的快照。

enter image description here

关于android - 布局的圆形矩形边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17774689/

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