20155301第十三周实验四总结

20155301第十三周实验四总结

Android Stuidio的安装测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章:

实验要求:

  • 安装 Android Stuidio
  • 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,提交代码运行截图和码云Git链接,截图没有学号要扣分
  • 学习Android Stuidio调试应用程序

实现过程:

res目录中存放了应用程序使用到的各种资源,如xml界面文件、图片、数据等。通常包含drawable子目录、layout子目录、values子目录三个。

1.drawable:存放分辨率不同的图片

2.layout:存放xml界面布局文件,主要用于显示用户操作界面

3.values:存放不同类型的数据,如string、array等
在实验中我们需要将"HelloWorld"改成"HelloWorld20155301"就可以完成了。

image

Activity测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章

实验要求:

  • 构建项目,运行教材相关代码
  • 创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

实现过程:

配置Activity
在文件AndroidManifest.xml中,只要为application...元素添加activity...子元素,并且调用它

image

UI测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章

实验要求:

  • 构建项目,运行教材相关代码
  • 修改代码让Toast消息中显示自己的学号信息
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

实现过程:

Toast是Android中用来显示信息的一种机制。
在activity_main中添加代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.dragon.toast.Main">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="20155301滕树晨"
        android:id="@+id/btn1"
        android:layout_alignParentTop="true"
        android:layout_marginTop="31dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

image

布局测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章

实验要求:

  • 构建项目,运行教材相关代码
  • 修改布局让P290页的界面与教材不同
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

实现过程:

ayout_gravity可以使用如下所示的取值:
1.top:将对象放在其容器的顶部,不改变其大小;

2.bottom:将对象放在其容器的底部,不改变其大小;

3.left:将对象放在其容器的左侧,不改变其大小;

4.certer_vertical:将对象纵向居中,不改变其大小,垂直方向上居中对齐;

 <Button
       android:id="@+id/cancelButton"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Cancel"
       tools:layout_editor_absoluteY="0dp"
       tools:layout_editor_absoluteX="0dp" />
    <Button
        android:id="@+id/saveButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/cancelButton"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp" />
    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:padding="4dp"
        android:layout_below="@id/cancelButton"
        android:layout_centerHorizontal="true"
        android:src="@android:drawable/ic_btn_speak_now"
        tools:layout_editor_absoluteY="285dp"
        tools:layout_editor_absoluteX="117dp" />
    <LinearLayout
        android:id="@+id/filter_button_container"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center|bottom"
        android:background="@android:color/white"
        android:orientation="horizontai"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="8dp">
        <Button
            android:id="@+id/filterButton"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Filter"
            tools:layout_editor_absoluteY="0dp"
            tools:layout_editor_absoluteX="0dp" />
    <Button
        android:id="@+id/shareButton"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="Share"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp" />
    <Button
        android:id="@+id/deleteButton"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="Delete"
        tools:layout_editor_absoluteY="129dp"
        tools:layout_editor_absoluteX="269dp" />

image

事件处理测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章

实验要求:

  • 构建项目,运行教材相关代码
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

实现过程:

当用户按下(或触碰)时钟的时候,会调用该方法并接受时钟对象。要修改时钟的颜色,需要调用其setBackgroundColor方法,传入一个颜色对象,从而实现触碰时钟改变颜色。

image

posted @ 2017-05-21 12:07  滕树晨  阅读(439)  评论(0编辑  收藏  举报