实验四 Android程序设计 实验报告 20162305李昱兴

实验四 Android程序设计 实验报告 20162305李昱兴

一、Android Studio的安装测试

1、有关该软件

  • Android Studio,是基于Itellij IDEA的一款流行的IDE。该软件包包含了Android SDK。SDK中包含了各种工具,包括一个不需要物理设备就能测试应用程序的模拟器。而Android Studio则提供了一个集成开发环境。

2、Android Studio的安装

  • 程序的安装可以参考Java For Android 2nd版教材的第24章教程指导,也可以按照娄老师的博客教程去做。
  • Android Studio安装教程

3、有关res

  • 当我们建立好了一个新的项目的时候,在APP中我们会发现有一个叫res的文件夹,res是resource的简写,这个文件夹当中包含着整个app的layout文件(布局),menu文件(菜单),mipmap(图像)文件,values(资源)文件,drawable(图片状态列表资源)文件。我们可以通过修改其中的一些代码,从而实现对app界面和其显示内容的修改。
  • HelloWorld显示截图
    1062726-20170601144930461-1653541200.png

1062726-20170601144942414-1089400104.png

二、Activity测试

1、什么是活动

  • 活动是Android.app.Activity类的一个实例。启动一个活动就意味着显示一个窗口。应用程序所创建的第一个窗口,叫作主窗口,它充当应用程序的入口点。Android应用程序可以包含多个活动,并且通过在应用程序清单文件中声明来指定主活动。

2、有关活动的一些代码

<LinearLayout 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=".SecondActivity">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

3、代码和活动截图

1062726-20170601145245868-1459761623.png

1062726-20170601145230680-289176802.png

三、UI测试

1、有关UI

  • UI即User Interface(用户界面)的简称。泛指用户的操作界面,包含移动APP,网页,智能穿戴设备等。UI设计主要指界面的样式,美观程度。而使用上,对软件的人机交互、操作逻辑、界面美观的整体设计则是同样重要的另一个门道。好的UI不仅是让软件变得有个性有品味,还要让软件的操作变得舒适、简单、自由,充分体现软件的定位和特点。使用UI工具所做的事情都会反应到布局当中文件当中,以XML元素的形式体现出来。要查看你生成了什么,单击UI工具底部的XML视图即可。

2、有关Toast

  • Toast是一个小的弹出对话框,用于显示一条消息作为给用户的反馈。Toast并不会替代当前的活动,并且只是占据了一条消息那么大的空间。
  • 如何在一个活动类中创建并显示一个Toast
Toast.makeText(this, "Downloading...", Toast.LENGTH_LONG).show();

3、实验结果测试截图

(实验截图)
1062726-20170601145328461-507720578.png

四、布局测试

1、有关LinearLayout

  • LinearLayout是根据orientation的属性,将子视图水平地或垂直地排列的一种布局。LinearLayout是最容易使用的布局。
  • 水平的LinearLayout

<LinearLayout     
xmlns:android="http://schemas.android.com/apk/res/android"     
xmlns:tools="http://schemas.android.com/tools"     
android:orientation="horizontal"    
android:layout_width="match_parent"   
android:layout_height="match_parent"> 
 
<ImageButton         
android:src="@android:drawable/btn_star_big_on"
android:layout_width="wrap_content"         
android:layout_height="wrap_content"/> 
     
<TextView         
android:layout_width="wrap_content"         
android:layout_height="wrap_content"         
android:text="@string/hello_world" />    

<Button 
android:text="Button1"         
android:layout_width="wrap_content"         
android:layout_height="wrap_content"/> 
 
</LinearLayout>
  • 垂直的LinaerLayout
<LinearLayout     
xmlns:android="http://schemas.android.com/apk/res/android"     
    xmlns:tools="http://schemas.android.com/tools"     
android:orientation="vertical"     
android:layout_width="match_parent"    
android:layout_height="match_parent">         
<ImageButton         
android:src="@android:drawable/btn_star_big_on"        
android:layout_gravity="center"         
android:layout_width="wrap_content"         
android:layout_height="wrap_content"/>     
<TextView        
android:layout_gravity="center"           
android:layout_width="wrap_content"         
android:layout_height="wrap_content"         
android:layout_marginLeft="15dp"         
android:text="@string/hello_world"/>    
<Button 
android:text="Button1"         
android:layout_gravity="center"               
android:layout_width="wrap_content"         
android:layout_height="wrap_content"/> 
</LinearLayout>

  • RelativeLayout
<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:paddingLeft="2dp"     
android:paddingRight="2dp">   
<Button       

android:id="@+id/cancelButton"         
android:layout_width="wrap_content"         
android:layout_height="wrap_content"         
android:text="Cancel" />     
<Button         
android:id="@+id/saveButton"         
android:layout_width="wrap_content"         
android:layout_height="wrap_content"         
android:layout_toRightOf="@id/cancelButton"         
android:text="Save" />       
<ImageView         

android:layout_width="150dp"         
android:layout_height="150dp"         
android:layout_marginTop="230dp"         
android:padding="4dp"         
android:layout_below="@id/cancelButton"         
android:layout_centerHorizontal="true"         
android:src="@android:drawable/ic_btn_speak_now" />     

<LinearLayout         
android:id="@+id/filter_button_container"     
android:layout_width="match_parent"         
android:layout_height="wrap_content"         
android:layout_alignParentBottom="true"         
android:gravity="center|bottom"     
android:background="@android:color/white"         
android:orientation="horizontal" >         

<Button             
android:id="@+id/filterButton"             
android:layout_width="wrap_content"             
android:layout_height="fill_parent"             
android:text="Filter" />        
  
<Button             
android:id="@+id/shareButton"             
android:layout_width="wrap_content"             
android:layout_height="fill_parent"             
android:text="Share" />        

<Button             
android:id="@+id/deleteButton"             
android:layout_width="wrap_content"            
android:layout_height="fill_parent"             
android:text="Delete" />     
</LinearLayout> 

</RelativeLayout> 

2、运行截图

1062726-20170601145622149-567303724.png

五、监听器

1、有关监听器

  • 大多数Android程序都是可交互的。通过Android框架所提供的事件驱动的编程泛型,用户可以很容易地与应用交互。要让程序响应某一个事件,需要为该事件编写一个监听器。

2、相关方法

OnClickListener  ——  onClick()
OnLongClickListner  ——   OnLongClick()
OnFocusChangeListener  ——  OnFocusChange()
OnKeyListener  ——  OnKey()
OnTouchListener  —— OnTouch()

3、实验成果截图

(实验截图)
1062726-20170601145712836-1053410609.jpg

六、代码托管

七、其他

  • 本次实验,我学习到了有关Android的一些知识,了解了Android Studio这个全新的集成开发环境。通过这部分的实验学习,我明白了Java的主要用途和用法,以Java为基础的集成环境的Android Studio也随着Android的广泛应用而变得十分重要在日后的学习中也要重视这部分的学习。

转载于:https://www.cnblogs.com/lyxwatm/p/6928903.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Activity界面是Android应用程序中的基本UI组件之一,用于展示用户界面和处理用户交互。实验中,我们可以通过以下步骤来创建和使用Activity界面。 首先,我们需要在Android项目中创建一个新的Activity类。可以通过右键点击项目目录中的Java文件夹,选择“新建”->“Activity”来创建一个新的Activity类。在创建过程中,我们可以选择模板、布局文件和Activity的名称等。 创建完Activity类后,我们需要在Activity的布局文件中定义界面UI组件,例如按钮、文本框、图像等。可以通过XML标记语言来创建和配置布局文件。在布局文件中,我们可以指定每个UI组件的位置、大小、样式等属性。 在Activity的代码中,我们可以通过findViewById()方法来获取布局文件中的UI组件的引用,并对它们进行操作。例如,我们可以在按钮上设置点击事件的监听器,当用户点击按钮时,会触发相应的方法。 我们还可以通过Intent对象在不同的Activity之间进行界面的切换。通过启动一个新的Activity,我们可以显示新的界面,并将数据传递给新的界面。 在实验中,我们可以定义一些基本的Activity界面,例如登录界面、注册界面、设置界面等。通过实验,我们可以熟悉Activity界面的创建、布局和交互操作等基本方法。此外,我们还可以通过实验来学习更高级的功能,如Activity之间的通信、Fragment的使用等。 总之,Activity界面是Android应用程序中最基本的界面组件之一,通过实验我们可以掌握创建、布局和操作Activity界面的基本方法,为开发更复杂的应用程序奠定基础。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值