如何在线性布局周围创建边框,如下图所示?

时间:2014-03-21 12:00:31

标签: android android-layout android-linearlayout

如何在线性布局周围创建边框,如下图所示? enter image description here

1 个答案:

答案 0 :(得分:2)

使用此布局xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8106a9"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="10dp"
    android:background="@drawable/lin_bg"
    android:orientation="vertical" >
</LinearLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/linearLayout1"
    android:layout_alignTop="@+id/linearLayout1"
    android:layout_marginLeft="28dp"
    android:layout_marginTop="-10dp"
    android:background="#8106a9"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:text="Sim Card"
    android:textColor="@android:color/white" />

和lin_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

<stroke
    android:width="3dp"
    android:color="@android:color/white" />

然后我得到如下布局

我希望这会对你有所帮助

enter image description here