Android一个登陆界面的设计


说起登陆界面的设计,大家可能都会说这个挺简单的的啊,弄个布局,加几个控件一个登陆界面就出来了,但我今天想说一下自己在设计一个登陆界面时遇到的问题,而我这个登陆界面的设计重点就是在一个水平布局上放了一个checkbox和一个登陆的button,在checkbox放上之后,之后的那个button在这个水平布局的空余空间上居中,这个对于高手来说可能不是什么问题了,而让我奇怪的是当我的布局属性设置为水平时,我的登陆button并不能居中,而只有在垂直的属性下button才能居中。

所以现在把这个代码贴出来,界面的效果并没有做什么美化,只是一些系统控件的组合。

选看一下效果图:

Android一个登陆界面的设计

所以这个设计的重点也就是在红色区域里让button居中。

下面是改布局的xml文件

 

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.     <LinearLayout android:layout_width="fill_parent"  
  7.                   android:layout_height="wrap_content">  
  8.         <TextView android:layout_width="wrap_content"  
  9.                   android:layout_height="wrap_content"  
  10.                   android:text="账号:"/>  
  11.         <EditText android:layout_width="240dip"  
  12.                   android:layout_height="wrap_content"  
  13.                   android:text="mumayi"  
  14.                   android:id="@+id/edtuser"/>  
  15.     </LinearLayout>  
  16.      <LinearLayout android:layout_width="fill_parent"  
  17.                   android:layout_height="wrap_content">  
  18.         <TextView android:layout_width="wrap_content"  
  19.                   android:layout_height="wrap_content"  
  20.                   android:text="密码:"/>  
  21.         <EditText android:layout_width="240dip"  
  22.                   android:layout_height="wrap_content"  
  23.                   android:password="true"  
  24.                   android:id="@+id/edtpsd"/>  
  25.     </LinearLayout>  
  26.     <LinearLayout  
  27.         android:layout_width="fill_parent"  
  28.         android:layout_height="fill_parent"  
  29.         android:orientation="horizontal" >  
  30.         <LinearLayout  
  31.             android:layout_width="wrap_content"  
  32.             android:layout_height="fill_parent"  
  33.             android:orientation="vertical" >  
  34.             <CheckBox  
  35.                 android:id="@+id/checkbox"  
  36.                 android:layout_width="wrap_content"  
  37.                 android:layout_height="wrap_content"  
  38.                 android:text="记住密码" />  
  39.         </LinearLayout>  
  40.         <LinearLayout  
  41.             android:layout_width="fill_parent"  
  42.             android:layout_height="fill_parent"  
  43.             android:orientation="vertical" >  
  44.             <Button  
  45.                 android:id="@+id/login"  
  46.                 android:layout_width="wrap_content"  
  47.                 android:layout_height="wrap_content"  
  48.                 android:layout_gravity="center_horizontal"  
  49.                 android:text="登录" />  
  50.         </LinearLayout>  
  51.     </LinearLayout>  
  52. </LinearLayout>  

相关内容