如何在Android LinearLayout周围创建边框? [英] How can I create a border around an Android LinearLayout?
本文介绍了如何在Android LinearLayout周围创建边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大布局,里面有一个小布局.
I have one big layout, and one smaller layout inside of it.
如何在小布局周围创建线条边框?
How do I create a line border around the small layout?
推荐答案
好的.您可以将边框添加到所需的任何布局.基本上,您需要创建一个自定义可绘制对象并将其作为背景添加到布局中.例如:
Sure. You can add a border to any layout you want. Basically, you need to create a custom drawable and add it as a background to your layout. example:
在可绘制文件夹中创建一个名为customborder.xml
的文件:
Create a file called customborder.xml
in your drawable folder:
<?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>
现在将其作为背景应用于较小的布局:
Now apply it as a background to your smaller layout:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/customborder">
应该可以解决问题.
另请参阅:
- http://tekeye.biz/2012/add-a-border-to-an-android-layout
- How to add border around linear layout except at the bottom?
这篇关于如何在Android LinearLayout周围创建边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文