總結(jié)一下android ui界面里面如何設(shè)置邊框,以及如何把邊框設(shè)置成弧形的即圓角。
其實(shí),android的ui里,界面一般都是比較簡(jiǎn)單的,不會(huì)像web頁(yè)面那樣,數(shù)據(jù)量比較大,關(guān)于給android界面(表格)設(shè)置邊框,其思想很想我們用HTML設(shè)計(jì)表格然后給它設(shè)置邊框,如果你懂html的話。即通過(guò)給不同的控件設(shè)置背景顏色來(lái)反襯出邊框線
以一個(gè)登錄界面為例,設(shè)置一個(gè)有邊框線的android 登錄界面:
注:本例要求的只是將該TableLayout中的行與行之間用邊框線隔開(kāi)
此例中,采用TableLayout布局,非常簡(jiǎn)單,里面有3個(gè)TableRow,分別放置 用戶名、密碼、登錄按鈕,根據(jù)上面說(shuō)的設(shè)置邊框線只需要設(shè)置控件的背景顏色即可。這個(gè)例子中要求行與行之間有邊框線,那么,就這么想,
TableLayout:是該界面的布局管理器(當(dāng)然也是一個(gè)控件),放在最外層,那么這時(shí)你可以給它選一個(gè)背景顏色參考注釋 a)
TableRow:是表格中的一行,設(shè)置邊框線重點(diǎn)就在此,它是緊跟著TableLayout的,可以給TableRow(行)設(shè)置背景色,參考b)
TableLayout與TableRow關(guān)系:可以看成父與子的關(guān)系,那么不管怎么樣,TableLayout總是大于TableRow,那么通過(guò)給二者設(shè)置不同的顏色,設(shè)置顏色的時(shí)候可以讓子組件(TableRow)周圍稍微留出一點(diǎn)邊界(就是它的背景色不會(huì)覆蓋完整個(gè)行,如何讓它顯示成這樣呢=====>android:layout_margin="0.5dip"[此屬性即是設(shè)置該組件周圍留出一點(diǎn)邊界])
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="
http://schemas.android.com/apk/res/android"
android:background="#ffcccccc" //a)給tablelayout設(shè)置背景色,改背景顏色將會(huì)是你要設(shè)置的邊框線的背景色android:layout_margin="1dip"
>
<!--android:background="@drawable/view_shape" -->
<TableRow
android:id="@+id/widget40"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99" //b)給tablerow設(shè)置背景色
android:layout_margin="0.5dip" //c)非常重要的一點(diǎn)>
<TextView
android:id="@+id/widget41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Name"
android:textStyle="bold"
android:layout_gravity="center_vertical"
//如果想讓表格里的列與列(column之間)也有邊框線隔開(kāi),則同上面一樣也要設(shè)置android:background="#ffffcc99"與android:layout_margin="0.5dip"
>
</TextView>
<EditText
android:id="@+id/widget42"
android:layout_width="141px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<TableRow
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99"
android:layout_margin="0.5dip"
>
<TextView
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textStyle="bold"
>
</TextView>
<EditText
android:id="@+id/widget45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<Button
android:id="@+id/widget46"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textColor="#ff000000"
android:layout_margin="2dip"
android:background="#ffffcc33"
>
<!--android:background="@drawable/view_shape" -->
</Button>
</TableLayout>