如何在Android中为Layout(RelativeLayout)设置图片边框?
答
你可以做的是创建一个自定义的可绘制形状,将应用作为将创建一个边框的ImageView的背景。
像下面的xml一样,你可以自己定制它。把它放在drawable/image_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
在drawbale
的文件夹中。在你的布局文件中加入这一行android:background="@drawable/customborder"
+0
我想使用图像(作为边框,内容图像是透明的),而不是纯色!你可以帮我吗 ? – user1465351 2012-07-07 06:12:25
答
你可以制作一张9幅图像作为背景。使中间透明并以您想要的方式填充边框。
下面是官方文档:http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
答
首先创建简单border.xml并保存到绘制
<?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"
图像后(作为边框),而不是纯色^^ – user1465351 2012-07-07 06:13:51
你尝试过吗?它将作为边界工作。 – 2012-07-07 06:21:09
使用图像使边界布局? – user1465351 2012-07-07 07:01:22