歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android一個登陸界面的設計

Android一個登陸界面的設計

日期:2017/3/1 10:51:03   编辑:Linux編程

說起登陸界面的設計,大家可能都會說這個挺簡單的的啊,弄個布局,加幾個控件一個登陸界面就出來了,但我今天想說一下自己在設計一個登陸界面時遇到的問題,而我這個登陸界面的設計重點就是在一個水平布局上放了一個checkbox和一個登陸的button,在checkbox放上之後,之後的那個button在這個水平布局的空余空間上居中,這個對於高手來說可能不是什麼問題了,而讓我奇怪的是當我的布局屬性設置為水平時,我的登陸button並不能居中,而只有在垂直的屬性下button才能居中。

所以現在把這個代碼貼出來,界面的效果並沒有做什麼美化,只是一些系統控件的組合。

選看一下效果圖:

所以這個設計的重點也就是在紅色區域裡讓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>
Copyright © Linux教程網 All Rights Reserved