如何在android relativelayout周围放置边框? [英] how to put a border around an android relativelayout?
本文介绍了如何在android relativelayout周围放置边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看到主题有关在Android周围放置边框textview,我用了它.但是现在,我想在位于相对布局中的小部件周围放置边框.我该怎么办?
I've seen this subject about puting a border around an android textview, and I used it. But now, I would like to put a border around widgets which are situated into a relative layout. How can I do it?
推荐答案
- 在您的
res/drawable
文件夹中,创建一个新文件background_border.xml
- in your
res/drawable
folder, create a new filebackground_border.xml
在此文件中,您将像这样定义小部件的背景:
In this file, you will define the background for widget like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- This is the stroke you want to define -->
<stroke android:width="1dp"
android:color="@color/color_stroke"/>
<!-- Optional, round your corners -->
<corners android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topRightRadius="0dp" />
<!-- Optional, fill the rest of your background with a color or gradient, use transparent if you only want the border to be displayed-->
<gradient android:startColor="@android:color/transparent"
android:endColor="@android:color/transparent"
android:angle="90"/>
</shape>
- 将小部件的背景设置为刚创建的可绘制配置
例如如果您想将边框放在相对布局上
eg. if you want to put your border on a relativelayout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_border"
android:padding="15dp">
...
</RelativeLayout>
这篇关于如何在android relativelayout周围放置边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文