[关闭]
@Heath 2015-10-22T14:14:56.000000Z 字数 4290 阅读 1582

实验一 基本 UI 界面设计

安卓实验报告


【实验目的】

  1. 熟悉 Android Studio 开发工具操作
  2. 熟悉 Android 基本 UI 开发,并进行 UI 基本设计

【实验内容】

  1. 实现如图 Android应用,实现如下显示效果(暂不要求控件点击事件效果)

    界面分析:
    整体界面布局为LinearLayout

    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. android:orientation="vertical"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent">
    5. </LinearLayout>

    界面最顶部是一个TextView

    1. <TextView
    2. android:layout_width="wrap_content"
    3. android:layout_height="wrap_content"
    4. android:text="Welcome To First Android Class!"
    5. android:layout_gravity="center"
    6. android:textColor="#00ff00"
    7. android:textSize="24sp"/>

    下面是一张图片,由ImagView实现

    1. <ImageView
    2. android:layout_width="wrap_content"
    3. android:layout_height="wrap_content"
    4. android:src="@drawable/crab"
    5. android:layout_gravity="center"/>

    用户名、密码部分可以用TableView来完成,密码输入框设置android:inputType="textPassword"

    1. <TableLayout
    2. android:layout_width="match_parent"
    3. android:layout_height="wrap_content"
    4. android:layout_margin="5dp">
    5. <TableRow>
    6. <TextView
    7. android:layout_width="wrap_content"
    8. android:layout_height="wrap_content"
    9. android:text="User:"/>
    10. <EditText
    11. android:layout_width="0dp"
    12. android:layout_height="wrap_content"
    13. android:layout_weight="1"
    14. android:hint="Input your user account here"/>
    15. </TableRow>
    16. <TableRow>
    17. <TextView
    18. android:layout_width="wrap_content"
    19. android:layout_height="wrap_content"
    20. android:text="Password:"/>
    21. <EditText
    22. android:layout_width="0dp"
    23. android:layout_height="wrap_content"
    24. android:layout_weight="1"
    25. android:inputType="textPassword"/>
    26. </TableRow>
    27. </TableLayout>

    为了下面两个按钮居中,用LinearLayout进行包裹,嵌套在根布局中

    1. <LinearLayout
    2. android:layout_width="wrap_content"
    3. android:layout_height="wrap_content"
    4. android:layout_gravity="center">
    5. <Button
    6. android:layout_width="wrap_content"
    7. android:layout_height="wrap_content"
    8. android:text="Login"/>
    9. <Button
    10. android:layout_width="wrap_content"
    11. android:layout_height="wrap_content"
    12. android:text="Register"/>
    13. </LinearLayout>

    最下方的进度条由ProcessBar实现,注意设置style

    1. <ProgressBar
    2. android:layout_width="wrap_content"
    3. android:layout_height="wrap_content"
    4. android:max="100"
    5. style="?android:attr/progressBarStyle"
    6. android:layout_gravity="center"/>
  2. 扩展部分

    界面分析:
    整体还是采用LinearLayout

    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. android:orientation="vertical"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent">
    5. </LinearLayout>

    顶部的文字和按钮用RelativeLayout来布局,设置背景颜色android:background="#fc01fb",按钮设置布局android:layout_alignParentRight="true"

    1. <RelativeLayout
    2. android:layout_width="wrap_content"
    3. android:layout_height="wrap_content"
    4. android:background="#fc01fb">
    5. <TextView
    6. android:layout_width="wrap_content"
    7. android:layout_height="wrap_content"
    8. android:text="个人信息"
    9. android:layout_alignParentLeft="true"/>
    10. <Button
    11. android:layout_width="wrap_content"
    12. android:layout_height="wrap_content"
    13. android:text="提交"
    14. android:layout_alignParentRight="true"
    15. android:layout_margin="3dp"
    16. android:id="@+id/submit_button"/>
    17. </RelativeLayout>

    图片和右侧表格、单选按钮使用LinearLayout嵌套TableLayout实现,单选按钮组件为RadioButton

    1. <LinearLayout
    2. android:layout_width="wrap_content"
    3. android:layout_height="wrap_content">
    4. <ImageView
    5. android:layout_width="wrap_content"
    6. android:layout_height="wrap_content"
    7. android:src="@drawable/avatar"/>
    8. <TableLayout
    9. android:layout_width="wrap_content"
    10. android:layout_height="wrap_content"
    11. android:orientation="vertical">
    12. <TableRow>
    13. <EditText
    14. android:layout_width="wrap_content"
    15. android:layout_height="wrap_content"
    16. android:hint="学号"/>
    17. </TableRow>
    18. <TableRow>
    19. <EditText
    20. android:layout_width="wrap_content"
    21. android:layout_height="wrap_content"
    22. android:hint="名字"/>
    23. </TableRow>
    24. <TableRow>
    25. <RadioGroup
    26. android:layout_width="wrap_content"
    27. android:layout_height="wrap_content"
    28. android:orientation="horizontal">
    29. <RadioButton
    30. android:layout_width="wrap_content"
    31. android:layout_height="wrap_content"
    32. android:text="男"/>
    33. <RadioButton
    34. android:layout_width="wrap_content"
    35. android:layout_height="wrap_content"
    36. android:text="女"/>
    37. </RadioGroup>
    38. </TableRow>
    39. </TableLayout>
    40. </LinearLayout>

    列表选项为Spinner,数据项在arrays.xml文件中定义

    1. <Spinner
    2. android:layout_width="match_parent"
    3. android:layout_height="wrap_content"
    4. android:entries="@array/info"/>
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <resources>
    3. <string-array name="info">
    4. <item>移动</item>
    5. <item>软院</item>
    6. <item>管理</item>
    7. <item>政务</item>
    8. <item>环境</item>
    9. </string-array>
    10. </resources>

    日期选取由DatePicker实现、

    1. <DatePicker
    2. android:layout_width="match_parent"
    3. android:layout_height="wrap_content"
    4. style="@android:style/Widget.DatePicker">
    5. </DatePicker>

【实验结果】

单击扩展按钮可跳转到扩展界面,在扩展界面单击提交可返回原界面
device-2015-10-22-213516.png-983.3kB
device-2015-10-22-213804.png-1242.6kB

【实验参考】

《第一行代码:Android》第三章 郭霖

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注