1. 程式人生 > >Android精美登入介面設計

Android精美登入介面設計

  在網上在到一個登入介面感覺挺不錯的,給大家分享一下~先看效果圖:


  這個Demo除了按鈕、小貓和Logo是圖片素材之外,其餘的UI都是通過程式碼實現的。

  一、背景

  背景藍色漸變,是通過一個xml檔案來設定的。程式碼如下:

  background_login.xml

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <shapexmlns:android="http://schemas.android.com/apk/res/android">
  3.     <gradient
  4.         android:startColor
    ="#FFACDAE5"
  5.         android:endColor="#FF72CAE1"
  6.         android:angle="45"
  7.     />
  8. </shape>

  startColor是漸變開始的顏色值,endColor是漸變結束的顏色值,angle是漸變的角度。其中#FFACDAE5中,FF是Alpha值,AC是RGB的R值,DA是RGB的G值,E5是RGB的B值,每個值在00~FF取值,即透明度、紅、綠、藍有0~255的分值,像要設定具體的顏色,可以在PS上的取色器上檢視設定。

  二、圓角白框

  效果圖上面的並不是白框,其實框是白色的,只是設定了透明值,也是靠一個xml檔案實現的。

  background_login_div.xml

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <shapexmlns:android="http://schemas.android.com/apk/res/android">
  3.     <solidandroid:color="#55FFFFFF"/>
  4.     <!-- 設定圓角  
  5.     注意: bottomRightRadius是左下角而不是右下角  bottomLeftRadius右下角-->
  6.     <cornersandroid:topLeftRadius
    ="10dp"android:topRightRadius="10dp"
  7.         android:bottomRightRadius="10dp"android:bottomLeftRadius="10dp"/>
  8. </shape>


  三、介面的佈局

  介面的佈局挺簡單的,就直接貼程式碼啦~

  login.xml

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:orientation="vertical"
  5.     android:layout_width="fill_parent"
  6.     android:layout_height="fill_parent"
  7.     android:background="@drawable/background_login">
  8.     <!-- padding 內邊距   layout_margin 外邊距  
  9.         android:layout_alignParentTop 佈局的位置是否處於頂部 -->
  10.     <RelativeLayout
  11.         android:id="@+id/login_div"
  12.         android:layout_width="fill_parent"
  13.         android:layout_height="wrap_content"
  14.         android:padding="15dip"
  15.         android:layout_margin="15dip"
  16.         android:background="@drawable/background_login_div_bg">
  17.         <!-- 賬號 -->
  18.         <TextView
  19.             android:id="@+id/login_user_input"
  20.             android:layout_width="wrap_content"
  21.             android:layout_height="wrap_content"
  22.             android:layout_alignParentTop="true"
  23.             android:layout_marginTop="5dp"
  24.             android:text="@string/login_label_username"
  25.             style="@style/normalText"/>
  26.         <EditText
  27.             android:id="@+id/username_edit"
  28.             android:layout_width="fill_parent"
  29.             android:layout_height="wrap_content"
  30.             android:hint="@string/login_username_hint"
  31.             android:layout_below="@id/login_user_input"
  32.             android:singleLine="true"
  33.             android:inputType="text"/>
  34.         <!-- 密碼 text -->
  35.         <TextView
  36.             android:id="@+id/login_password_input"
  37.             android:layout_width="wrap_content"
  38.             android:layout_height="wrap_content"
  39.             android:layout_below="@id/username_edit"
  40.             android:layout_marginTop="3dp"
  41.             android:text="@string/login_label_password"
  42.             style="@style/normalText"/>
  43.         <EditText
  44.             android:id="@+id/password_edit"
  45.             android:layout_width="fill_parent"
  46.             android:layout_height="wrap_content"
  47.             android:layout_below="@id/login_password_input"
  48.             android:password="true"
  49.             android:singleLine="true"
  50.             android:inputType="textPassword"/>
  51.         <!-- 登入button -->
  52.         <Button
  53.             android:id="@+id/signin_button"
  54.             android:layout_width="wrap_content"
  55.             android:layout_height="wrap_content"
  56.             android:layout_below="@id/password_edit"
  57.             android:layout_alignRight="@id/password_edit"
  58.             android:text="@string/login_label_signin"
  59.             android:background="@drawable/blue_button"/>
  60.     </RelativeLayout>
  61.     <RelativeLayout
  62.         android:layout_width="fill_parent"
  63.         android:layout_height="wrap_content">
  64.          <TextViewandroid:id="@+id/register_link"
  65.              android:text="@string/login_register_link"
  66.              android:layout_width="wrap_content"
  67.              android:layout_height="wrap_content"
  68.              android:layout_marginLeft="15dp"
  69.              android:textColor="#888"
  70.              android:textColorLink="#FF0066CC"/>
  71.         <ImageViewandroid:id="@+id/miniTwitter_logo"
  72.             android:src="@drawable/cat"
  73.             android:layout_width="wrap_content"
  74.             android:layout_height="wrap_content"
  75.             android:layout_alignParentRight="true"
  76.             android:layout_alignParentBottom="true"
  77.             android:layout_marginRight="25dp"
  78.             android:layout_marginLeft="10dp"
  79.             android:layout_marginBottom="25dp"/>
  80.         <ImageViewandroid:src="@drawable/logo"
  81.             android:layout_width="wrap_content"
  82.             android:layout_height="wrap_content"
  83.             android:layout_toLeftOf="@id/miniTwitter_logo"
  84.             android:layout_alignBottom="@id/miniTwitter_logo"
  85.             android:paddingBottom="8dp"/>
  86.     </RelativeLayout>
  87. </LinearLayout>


  四、Java原始檔

  Java原始檔比較簡單,只是例項化Activity,去掉標題欄。