Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中为布局(RelativeLayout)设置图像边框?_Android_Border - Fatal编程技术网

如何在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"