湖南某科技大学 安卓Android移动开发基础期中考试笔记(持续更新)

湖南某科技大学 安卓Android移动开发基础期中考试笔记

前言

建议大家把第三章的三个实战演练和本笔记的所有代码部分都在AS中手打一遍,手打的意思是看懂之后自己写出来,而不是照着抄。这不90分就到手了?

第一章 基础

  • Android是一款基于Linux平台的开源操作系统,主要用于移动开发中。

  • Android体系结构

    Android 操作系统的架构示意图

    一个实例:闹钟->通知管理器->多媒体框架->音频驱动

    1. 应用程序层(application)

      应用程序层是一个核心应用程序的集合,所以安装在手机上的应用程序都在这一层。例如:系统自带的联系人程序、短信程序、下载的小游戏。

    2. 应用程序框架层(application framework) Android SDK 和这一层有关

      应用程序框架层主要提供构建应用程序时用到的各种API。例如:视图(View)、活动管理器(activity manager)、通知管理器(notification manager)。

    3. 核心类库(libraries)

      • 核心类库包含系统库和Android运行时库
      • 系统库这一层主要通过c/c++来为Android系统提供主要的特性支持。例如:OpenGL/ES库提供类3D绘图的支持、Webkit库提供浏览器内核的支持。
      • Android运行时库(android runtime)主要提供了一些核心库,能够允许开发者使用Java语言来编写Android程序。
    4. Linux内核(Linux Kernel) 驱动

      Linux内核为Android设备的各种硬件提供了底层的驱动。例如:显示驱动、音频驱动。

  • Android程序结构

  • img

    • manifests

      用于存放AndroidManifest.xml文件,整个项目的配置文件。注册四大组件、添加权限。

      <?xml version = "1.0" encoding="utf-8"?>
      <manifest xmls:android="http://schemas.anroid.com/apk/res/android"
          package="cn.itcast.myapplication" >
          <application
              android:allowBackup="true"  //设置应用数据能够被备份或恢复。
              android:icon="@mipmap/ic_launcher"  //设置图标。
              android:label="HelloWorld"  //设置应用程序名
              android:supportsRtl="true"  //设置允许RTL(从右到左布局)。
              android:theme="@style/AppTheme" >  //设置主题。
              <activity android:name=".MainActivity" >
              	<intent-filter>
                  	<action anroid:name="android.intent.action.MAIN" />
                      <category android:name="android.intent.category.LAUNCHER"
                  </intent-filter>
              </activity>
          </application>
      
      </manifest>
      
    • java

      用于存放所有的Java代码。

    • res

      • drawable

        用于存放图片及XML文件

      • layout

        存放布局文件

      • mipmap

        用于存放应用程序图标

      • value

        用于放置定义的字符串

    • Gradle Scripts

      存放项目相关文件

第二章 UI

  • 线性布局

    • android:orientation属性,有vertical和horizontal(默认)两个值

    • android:layout_width和android:layout_heigh两个属性,有match_parent(继承父组件大小)、wrap_content(内容大小)两个值或者是数值。

    • android:layout_weight(权重),值为数字,带引号。使用weight属性时,控件宽度不再由width决定,使用width一般设置为0dp。

  • 相对布局

    • 设置控件位置的属性

      以下属性值为true或false

      • android:layout_centerParent 设置当前控件位于父布局的中央位置
      • android:layout_centerVertical 设置当前控件位于父布局垂直居中位置
      • anroid:layout_centerHorizontal 设置当前控件位于父布局水平居中位置
      • anroid:layout_alignParentTop 设置当前控件与父控件顶端对齐
      • android:layout_alignParentBottom 设置当前控件与父控件底端对齐
      • android:layout_alignParentLeft 设置当前控件与父控件左对齐
      • android:layout_alignParentRight 设置当期控件与父控件右对齐

      以下属性值为某控件的ID

      • android:layout_above 设置当前控件位于某控件的上方
      • android:layout_below 设置当前控件位于某控件的下方
      • android:layout_toLeftOf 设置当前控件位于某控件的左边
      • android:layout_toRightOf 设置当前控件位于某控件的右边
      • android:layout_alignTop 设置当前控件与某控件顶端对齐
      • android:layout_alignBottom 设置当前控件与某控件底端对齐
      • android:layout_alignLeft 设置当前控件与某控件左对齐
      • android:layout_alignRight 设置当前控件与某控件右对齐
    • 设置某控件 间距的属性

      某控件指的是?

      • android:layout_marginTop 设置当前控件上边界与某控件的距离
      • android:layout_marginBottom 设置当前控件下边界与某控件的距离
      • android:layout_marginLeft 设置当前控件左边界与某控件的距离
      • android:layout_marginRight 设置当前控件有边界与某控件的距离
    • 设置布局内边距的属性

      • android:paddingTop 设置布局顶部内边距的距离
      • android:paddingBottom 设置布局底部内边距的距离
      • android:paddingLeft 设置布局左边内边距的距离
      • android:paddingRight 设置布局右边内边距的距离
  • 表格布局

    序号从0开始

    TableLayout布局属性

    • android:stretchColumns 设置某列被拉伸
    • android:shrinkColumns 设置某列被收缩
    • android:collapseColumns 设置某列被隐藏

    TableLayout控件属性

    • android:layout_column 设置该控件显示位置
    • android:layout_span 设置该单元格占几列,默认为一列
  • LogCat的使用

    Log类日志输出六个级别(从低到高)

    1. Verbose Log.v(String, String)
    2. Debbug Log.d(String, String)
    3. Info Log.i(String, String)
    4. Warning Log.w(String, String)
    5. Error Log.e(String, String)
    6. Assert 没有对应的静态方法 级别最高

第三章 Activity

Activity的生命周期

  1. 生命周期状态

    1. 启动状态
    2. 运行状态
    3. 暂停状态
    4. 停止状态
    5. 销毁状态
  2. 生命周期方法

    1. onCreate()

      activity创建时调用

    2. onStart()

      activity即将可见时调用

    3. onResume()

      activity获取焦点与用户开始交互时调用

    4. onPause()

      activity被其他activity覆盖或锁屏时调用

    5. onDestroy()

      activity被销毁时调用

    6. onRestart()

      activity从停止状态再次启动时调用

Activity的启动模式

​ 在AndroidManifest.xml中,通过标签的anroid:launchMode属性可以设置启动模式。

  1. standard模式

    默认启动模式,每启动一个activity就会在栈顶创建一个新的实例,闹钟程序通常采用此方式

  2. singleTop模式

    先判断启动的activity实例是否位于栈顶,如果位于栈顶则直接复用,浏览器的书签通常采用此模式

  3. singleTask模式

    先检查栈中是否存在当前activity实例,如果存在,则直接使用,此实例之上的所有实例全部出栈

  4. singleInstance模式

    启动一个新的任务栈来管理activity实例,无论从哪个任务栈中启动该activity,该实例在系统中只有一个。

Activity之间的跳转

  1. 显式意图

    Intent intent = new Intent(this, Ativity02.class);
    startActivity(intent);
    
  2. 隐式意图

    MainActivity.java

    Intent intent = new Intent();
    intent.setAction("cn.itcast.START_ACTIVITY");
    startActivity(intent);
    

    AndroidManifest.xml

    <activity android:name="cn.itcast.Activity02">
    	<intent-filter>
        	<action android:name="cn.itcast.START_ACTIVITY" />
            <category android:name="anroid.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    
  3. 打开浏览器实现

    MainActivity.java

    public class MainActivity extends AppCompatActivity{
         
        @Override
        protected void onCreate(Bundle bundle){
         
            super.onCreate(bundle);
            setContentView(R.layout.activity_main);
            Button button = (Button)findViewById(R.id.main_button);
            button.setOnClickListence(new View.OnClickListence()</
  • 9
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呼呼呼呼~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值