一直以来,圆角的边框看起来很舒服。下面就是一个完整的圆角边框登录界面的布局文件。
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>
下面是登录界面的效果图: