如何在Android中为布局(RelativeLayout)设置图像边框?
我想使用的边框图像如下: 为布局设置边框。。。?如何在Android中为布局(RelativeLayout)设置图像边框?,android,border,Android,Border,我想使用的边框图像如下: 为布局设置边框。。。? 我应该这样做吗?您可以创建一个自定义的可绘制形状,该形状将作为ImageView的背景,该背景将创建一个边框 类似于下面的xml,您可以自己定制它。将其放入drawable/image\u border.xml中 <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" >
我应该这样做吗?您可以创建一个自定义的可绘制形状,该形状将作为ImageView的背景,该背景将创建一个边框 类似于下面的xml,您可以自己定制它。将其放入drawable/image\u border.xml中
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="1dp"
android:color="#000000" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
</shape>
将其作为ImageView的背景应用。它应该为您的ImageView创建边框。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /></shape>
将此文件另存为
customborder.xml
文件夹中的trable
文件。在布局文件中添加这一行android:background=“@drawable/customborder”
您可以制作一个9-patch图像作为背景应用。使中间透明,并按您想要的方式填充边框
以下是官方文档:首先创建simple border.xml并保存到drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<corners android:radius="15dip" />
<solid android:color="#00000000" />
<stroke android:width="2dp" android:color="#000000"/>
</shape>
</item>
</layer-list>
我想用图像(作为边框,带内容的图像是透明的),而不是纯色!你能帮我吗?图像(作为边框),而不是纯色^^使用图像为版面制作边框吗?不,只需将此版面作为背景应用于要添加边框的版面。
android:background="@drawable/imageee_color"