Android開發系列---UI篇---簡單的圓角邊框登錄界面


  一直以來,圓角的邊框看起來很舒服。下面就是一個完整的圓角邊框登錄界面的布局文件。

1、首先在res/drawable目錄下面建立一個設置圓角邊框參數的xml文件,如下:

corner_round.xml:

<?xml version="1.0" encoding="utf-8"?>   
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFCC33"/>
<corners android:topLeftRadius="10dp"
android:topRightRadius
="10dp"
android:bottomRightRadius
="10dp"
android:bottomLeftRadius
="10dp"/>
</shape>

上面的solid實心,也就是用來設置邊框背景色的。corners圓角,用來設置邊框的圓角半徑。在這個xml里面還可以設置描邊stroke、漸變gradient、填充padding元素。

2、之后在布局文件中background元素引用corner_round.xml就行了。

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:background
="#FFFFFF"
android:orientation
="vertical" >

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height
="wrap_content"
android:layout_margin
="10dip"
android:background
="@drawable/corner_round" >

<LinearLayout
android:id="@+id/layout_top"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:paddingLeft
="10dip"
android:paddingRight
="10dip"
android:paddingTop
="20dip" >

<TextView
android:id="@+id/username"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="用戶名:"
android:textColor
="#000000" />

<EditText
android:id="@+id/username_tx"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:layout_toRightOf
="@id/username" />
</LinearLayout>

<LinearLayout
android:id="@+id/layout_center"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:layout_below
="@id/layout_top"
android:paddingLeft
="10dip"
android:paddingRight
="10dip"
android:paddingTop
="10dip" >

<TextView
android:id="@+id/password"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="密 碼:"
android:textColor
="#000000" />

<EditText
android:layout_width="fill_parent"
android:layout_height
="wrap_content"
android:layout_toRightOf
="@id/password"
android:password
="true" />
</LinearLayout>

<TextView
android:layout_width="fill_parent"
android:layout_height
="1dip"
android:layout_below
="@id/layout_center"
android:background
="#FFFFFF" />

<LinearLayout
android:id="@+id/layout_center_two"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:layout_below
="@id/layout_center"
android:orientation
="horizontal"
android:paddingLeft
="10dip"
android:paddingRight
="10dip" >

<CheckBox
android:layout_width="fill_parent"
android:layout_height
="wrap_content"
android:layout_weight
="1"
android:text
="保存密碼"
android:textColor
="#000000"
android:textSize
="13sp" />

<TextView
android:layout_width="fill_parent"
android:layout_height
="wrap_content"
android:layout_weight
="1"
android:paddingLeft
="20dip"
android:text
="忘記密碼?"
android:textColor
="#0000FF" />
</LinearLayout>

<TextView
android:layout_width="fill_parent"
android:layout_height
="1dip"
android:layout_below
="@id/layout_center_two"
android:background
="#FFFFFF" />

<LinearLayout
android:id="@+id/layout_center1"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:layout_below
="@id/layout_center_two"
android:orientation
="horizontal"
android:paddingLeft
="10dip"
android:paddingRight
="10dip"
android:paddingTop
="10dip" >

<Button
android:layout_width="fill_parent"
android:layout_height
="wrap_content"
android:layout_weight
="1"
android:gravity
="center"
android:text
="登錄" />

<Button
android:layout_width="fill_parent"
android:layout_height
="wrap_content"
android:layout_weight
="1"
android:gravity
="center"
android:text
="退出" />
</LinearLayout>
</RelativeLayout>

</LinearLayout>


下面是登錄界面的效果圖:





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM