如何在 Android 布局周围创建边框,如附加图像?

How can I create a border around an Android layout like attached image?

我在需要创建边框布局时遇到问题,但我做不到。

如何像附加图片一样创建边框?

https://i.stack.imgur.com/pV804.png

您可以为任何您想要的布局添加边框。只需使用名称 customborder 创建自定义布局并添加 xml 代码

 <?xml version="1.0" encoding="UTF-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
   <corners android:radius="20dp"/> 
   <padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
   <stroke android:width="1dp" android:color="#CCCCCC"/>
 </shape>

然后只需像这样将背景添加到布局中

<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/customborder">

希望对您有所帮助。

试试这个:

第 1 步:使用空白数据

创建 9patch 边框图像 here

第 2 步:在布局背景中设置此图像并管理顶部、左侧、右侧和底部的填充