在我的应用程序中,我将使用很多布局“边框”,它们是一个简单的圆角矩形。为了测试它的外观,我创建了一个具有透明背景的 .png 文件:
我只是将图像设置为我的布局背景。问题是我需要为其他布局使用不同的比例,而在 Photoshop 中为我的所有布局创建这样的图像会浪费时间。
问题:我怎样才能对 android API(可能是 XML 形状)做同样的事情,但允许矩形被拉伸到任何尺寸并且仍然保持锐利?
在我的应用程序中,我将使用很多布局“边框”,它们是一个简单的圆角矩形。为了测试它的外观,我创建了一个具有透明背景的 .png 文件:
我只是将图像设置为我的布局背景。问题是我需要为其他布局使用不同的比例,而在 Photoshop 中为我的所有布局创建这样的图像会浪费时间。
问题:我怎样才能对 android API(可能是 XML 形状)做同样的事情,但允许矩形被拉伸到任何尺寸并且仍然保持锐利?
您可以使用可绘制
在可绘制文件夹中有 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 时图形编辑器的快照。
Shape drawable应该这样做。例如:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp" />
<solid android:color="@android:color/transparent" />
<stroke android:width="2dp" android:color="#0000ff" />
</shape>