android布局实践(二)login界面

傷城~ 2022-08-20 11:28 353阅读 0赞

1、主界面login.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@color/white"
  6. android:orientation="vertical" >
  7. <LinearLayout
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. android:background="@color/white"
  11. android:layout_margin="20dp"
  12. android:orientation="vertical" >
  13. <!-- 输入框内容 -->
  14. <LinearLayout
  15. android:layout_width="match_parent"
  16. android:layout_height="0dp"
  17. android:layout_weight="3"
  18. android:layout_marginBottom="20dp"
  19. android:orientation="horizontal"
  20. >
  21. <!-- logo -->
  22. <LinearLayout
  23. android:layout_width="0dp"
  24. android:layout_height="match_parent"
  25. android:layout_weight="1"
  26. android:background="@drawable/logo4"
  27. >
  28. </LinearLayout>
  29. <!-- 输入框 -->
  30. <LinearLayout
  31. android:layout_width="0dp"
  32. android:layout_height="match_parent"
  33. android:layout_weight="2"
  34. android:layout_marginLeft="20dp"
  35. android:orientation="vertical"
  36. >
  37. <!-- 账号-->
  38. <LinearLayout
  39. android:layout_width="match_parent"
  40. android:layout_height="0dp"
  41. android:layout_weight="1"
  42. android:background="@drawable/login_username"
  43. android:layout_marginBottom="8dp"
  44. >
  45. <RelativeLayout
  46. android:layout_width="match_parent"
  47. android:layout_height="match_parent"
  48. >
  49. <EditText
  50. android:id="@+id/username"
  51. android:layout_width="match_parent"
  52. android:layout_height="match_parent"
  53. android:layout_marginLeft="15sp"
  54. android:layout_marginRight="15sp"
  55. android:hint="请输入雷霆账号"
  56. android:textColor="@android:color/darker_gray"
  57. android:background="@null"
  58. />
  59. <ImageView
  60. android:layout_width="20dp"
  61. android:layout_height="20dp"
  62. android:background="@drawable/list_20_50"
  63. android:layout_centerVertical="true"
  64. android:layout_alignRight="@id/username"
  65. />
  66. </RelativeLayout>
  67. </LinearLayout>
  68. <!-- 密码-->
  69. <LinearLayout
  70. android:layout_width="match_parent"
  71. android:layout_height="0dp"
  72. android:layout_weight="1"
  73. android:background="@drawable/login_username"
  74. android:layout_marginBottom="8dp"
  75. >
  76. <EditText
  77. android:id="@+id/password"
  78. android:layout_width="match_parent"
  79. android:layout_height="match_parent"
  80. android:layout_marginLeft="15sp"
  81. android:layout_marginRight="15sp"
  82. android:background="@null"
  83. android:hint="请输入登录密码"
  84. android:inputType="textPassword"
  85. android:textColor="@android:color/darker_gray" />
  86. </LinearLayout>
  87. <!-- 确认按钮-->
  88. <LinearLayout
  89. android:layout_width="match_parent"
  90. android:layout_height="0dp"
  91. android:layout_weight="1"
  92. android:background="#478ce0"
  93. android:gravity="center"
  94. >
  95. <TextView
  96. android:id="@+id/login_submit"
  97. android:layout_width="wrap_content"
  98. android:layout_height="wrap_content"
  99. android:text="登录"
  100. android:textColor="@color/white"
  101. android:textSize="20sp"
  102. android:layout_gravity="center"
  103. />
  104. </LinearLayout>
  105. </LinearLayout>
  106. </LinearLayout>
  107. <LinearLayout
  108. android:layout_width="match_parent"
  109. android:layout_height="0dp"
  110. android:layout_weight="1"
  111. android:orientation="vertical" >
  112. <!-- 分隔符 -->
  113. <LinearLayout
  114. android:layout_width="match_parent"
  115. android:layout_height="1dp"
  116. android:background="@android:color/darker_gray" >
  117. </LinearLayout>
  118. <!-- 4个链接 -->
  119. <LinearLayout
  120. android:layout_width="match_parent"
  121. android:layout_height="match_parent"
  122. android:layout_marginTop="10dp"
  123. android:orientation="horizontal"
  124. >
  125. <!-- 修改密码 -->
  126. <LinearLayout
  127. android:layout_width="0dp"
  128. android:layout_height="match_parent"
  129. android:layout_weight="1" >
  130. <LinearLayout
  131. android:layout_width="match_parent"
  132. android:layout_height="match_parent"
  133. android:gravity="center_vertical"
  134. >
  135. <ImageView
  136. android:layout_width="@dimen/login_link_size"
  137. android:layout_height="@dimen/login_link_size"
  138. android:background="@drawable/lock"
  139. />
  140. <TextView
  141. android:layout_width="wrap_content"
  142. android:layout_height="wrap_content"
  143. android:text="修改密码"
  144. android:textColor="@color/login_link_text_color"
  145. />
  146. </LinearLayout>
  147. </LinearLayout>
  148. <!-- 分隔符 -->
  149. <LinearLayout
  150. android:layout_width="1dp"
  151. android:layout_height="match_parent"
  152. android:background="@android:color/darker_gray" >
  153. </LinearLayout>
  154. <!-- 忘记密码 -->
  155. <LinearLayout
  156. android:layout_width="0dp"
  157. android:layout_height="match_parent"
  158. android:layout_weight="1" >
  159. <LinearLayout
  160. android:layout_width="match_parent"
  161. android:layout_height="match_parent"
  162. android:gravity="center_vertical"
  163. >
  164. <ImageView
  165. android:layout_width="@dimen/login_link_size"
  166. android:layout_height="@dimen/login_link_size"
  167. android:background="@drawable/lock_open"
  168. android:layout_marginLeft="5dp"
  169. />
  170. <TextView
  171. android:layout_width="wrap_content"
  172. android:layout_height="wrap_content"
  173. android:text="忘记密码"
  174. android:textColor="@color/login_link_text_color"
  175. />
  176. </LinearLayout>
  177. </LinearLayout>
  178. <!-- 分隔符 -->
  179. <LinearLayout
  180. android:layout_width="1dp"
  181. android:layout_height="match_parent"
  182. android:background="@android:color/darker_gray" >
  183. </LinearLayout>
  184. <!-- 注册账号 -->
  185. <LinearLayout
  186. android:layout_width="0dp"
  187. android:layout_height="match_parent"
  188. android:layout_weight="1" >
  189. <LinearLayout
  190. android:layout_width="match_parent"
  191. android:layout_height="match_parent"
  192. android:gravity="center_vertical"
  193. >
  194. <ImageView
  195. android:layout_width="@dimen/login_link_size"
  196. android:layout_height="@dimen/login_link_size"
  197. android:background="@drawable/person_05"
  198. android:layout_marginLeft="5dp"
  199. />
  200. <TextView
  201. android:layout_width="wrap_content"
  202. android:layout_height="wrap_content"
  203. android:text="注册账号"
  204. android:textColor="@color/login_link_text_color"
  205. />
  206. </LinearLayout>
  207. </LinearLayout>
  208. <!-- 分隔符 -->
  209. <LinearLayout
  210. android:layout_width="1dp"
  211. android:layout_height="match_parent"
  212. android:background="@android:color/darker_gray" >
  213. </LinearLayout>
  214. <!-- 联系客服 -->
  215. <LinearLayout
  216. android:layout_width="0dp"
  217. android:layout_height="match_parent"
  218. android:layout_weight="1" >
  219. <LinearLayout
  220. android:layout_width="match_parent"
  221. android:layout_height="match_parent"
  222. android:gravity="center_vertical"
  223. >
  224. <ImageView
  225. android:layout_width="@dimen/login_link_size"
  226. android:layout_height="@dimen/login_link_size"
  227. android:background="@drawable/service_06"
  228. android:layout_marginLeft="5dp"
  229. />
  230. <TextView
  231. android:layout_width="wrap_content"
  232. android:layout_height="wrap_content"
  233. android:text="联系客服"
  234. android:textColor="@color/login_link_text_color"
  235. />
  236. </LinearLayout>
  237. </LinearLayout>
  238. </LinearLayout>
  239. </LinearLayout>
  240. </LinearLayout>
  241. </LinearLayout>

2、数值

2.1 颜色 color.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <color name="transparent_background">#50000000</color>
  4. <color name="red">#FF0000</color>
  5. <color name="white">#FFFFFF</color>
  6. <color name="black">#000000</color>
  7. <color name="text_color">#5997e2</color>
  8. <color name="login_link_text_color">#5997e2</color>
  9. </resources>

2.2 值 dimens.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <dimen name="icon_size">20dp</dimen>
  4. <!-- 登录界面图标尺寸 -->
  5. <dimen name="icon_size_login_bg">50dp</dimen>
  6. <dimen name="icon_size_login">40dp</dimen>
  7. <dimen name="icon_size_login_press">55dp</dimen>
  8. <dimen name="icon_size_login_small">13dp</dimen>
  9. <!-- 登录界面文字大小 -->
  10. <dimen name="margin_top_text_login">7dp</dimen>
  11. <!-- 登录界面文字marginTop值 -->
  12. <dimen name="text_size_login">14sp</dimen>
  13. <!-- logo尺寸 -->
  14. <dimen name="logo_width">150dp</dimen>
  15. <dimen name="logo_height">30dp</dimen>
  16. <!-- 登录界面4个链接的尺寸 -->
  17. <dimen name="login_link_size">30dp</dimen>
  18. </resources>

3、图形

3.1 输入框样式 login_username.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  3. <stroke
  4. android:width="1dp"
  5. android:color="@android:color/darker_gray"
  6. />
  7. </shape>

代码中打开页面代码:

  1. private void openHomeView(){
  2. final AlertDialog dialog = new AlertDialog.Builder(LeitingActivityUtils.getActivity()).create();
  3. dialog.show();
  4. final Window window = dialog.getWindow();
  5. window.setContentView(R.layout.home);
  6. // 获取宽高
  7. WindowManager wm = window.getWindowManager();
  8. final int height = wm.getDefaultDisplay().getHeight();
  9. final int width = wm.getDefaultDisplay().getWidth();
  10. LayoutParams lp = window.getAttributes();
  11. // 设置窗体的宽高
  12. lp.height = (int)(height * 0.7);
  13. lp.width = (int)(width * 0.7);
  14. window.setAttributes(lp);
  15. ImageView forgetPwd = (ImageView) window.findViewById(R.id.forget_pwd);
  16. ImageView register = (ImageView) window.findViewById(R.id.regiser);
  17. ImageView registeredLogin = (ImageView) window.findViewById(R.id.registered_login);
  18. ImageView visitor = (ImageView) window.findViewById(R.id.visitor);
  19. // 已有账号登录
  20. registeredLogin.setOnClickListener(new View.OnClickListener() {
  21. @Override
  22. public void onClick(View v) {
  23. // 打开已有账号登录界面
  24. window.setContentView(R.layout.login);
  25. }
  26. });
  27. }

成品展示:

Center

Center 1

发表评论

表情:
评论列表 (有 0 条评论,353人围观)

还没有评论,来说两句吧...

相关阅读