【Android】Android快速入门教程(五——2)——常见控件的使用方式


android studio中打开之前创建的 Hello World项目

一、布局控件

布局控件,顾名思义就是对你的页面提供布局方式,让你的app页面中的其他控件(例如文本控件,按钮控件)可以合理有序的安排位置。

  1. 找到如下图所示的activity_main.xml文件,并切换为Design的设计页面
    在这里插入图片描述
  2. 你会发现如下图所示有很多布局控件,但是我们常用的布局控件就是FrameLayout,LinearLayout,ConstraintLayout,还有一个里面没有列出的RelativeLayout布局,但是ConstraintLayout完全可以替代RelativeLayout布局,所以这里就不介绍RelativeLayout布局了
    在这里插入图片描述
    1. FrameLayout(帧布局)可以说是最为简单的一个布局,这个布局直接在屏幕上开辟出一块空白的区域,当我们往里面添加控件的时候,会默认把他们放到这块区域的左上角,而这种布局方式却没有任何的定位方式,所以它应用的场景并不多;帧布局的大小由控件中最大的子控件决定,如果控件的大小一样大的话,那么同一时刻就只能看到最上面的那个组件!后续添加的控件会覆盖前一个!虽然默认会将控件放置在左上角,但是我们也可以通过layout_gravity属性,指定到其他的位置!
      FrameLayout的属性很少就两个,但是在说之前我们先介绍一个东西:
      前景图像:永远处于帧布局最上面,直接面对用户的图像,就是不会被覆盖的图片。
      两个属性:
      android:foreground:设置改帧布局容器的前景图像
      android:foregroundGravity:设置前景图像显示的位置
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:foreground="@mipmap/ic_launcher_round"
        android:foregroundGravity="left|bottom">
        <TextView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="center"
            android:foreground="@mipmap/ic_launcher_round"
            android:foregroundGravity="right|bottom"
            android:background="#FF6143" />
        <TextView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:background="#7BFE00" />
        <TextView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#FFFF00" />
    </FrameLayout>
    
    效果图如下图所示
    在这里插入图片描述
    1. LinearLayout(线性布局)是使用比较多的一个布局控件,通常用于控件垂直或者水平排序的页面,android:orientation=""这个属性就是控制垂直(android:orientation="vertical")或者水平(android:orientation="horizontal")排序,用的比较多的自身属性为android:gravity="",这个是控制子控件所在的位置,当然它还有很多通用属性,这里就不一一介绍了,有兴趣的可以向度娘提问。它的子控件用得最多的属性为android:layout_gravity="",这个是控制子控件自身相对父布局LinearLayout(线性布局)的位置。
      水平排序:
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:orientation="horizontal"
          android:layout_height="match_parent">
          <TextView
              android:layout_width="200dp"
              android:layout_height="200dp"
              android:background="#FF6143" />
          <TextView
              android:layout_width="150dp"
              android:layout_height="150dp"
              android:background="#7BFE00" />
          <TextView
              android:layout_width="100dp"
              android:layout_height="100dp"
              android:background="#FFFF00" />
      </LinearLayout>
      
      效果图
      在这里插入图片描述
      垂直排序:
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:orientation="vertical"
          android:layout_height="match_parent">
          <TextView
              android:layout_width="200dp"
              android:layout_height="200dp"
              android:background="#FF6143" />
          <TextView
              android:layout_width="150dp"
              android:layout_height="150dp"
              android:background="#7BFE00" />
          <TextView
              android:layout_width="100dp"
              android:layout_height="100dp"
              android:background="#FFFF00" />
      </LinearLayout>
      
      效果图
      在这里插入图片描述
    2. ConstraintLayout,扣心自问,这个布局我真的很少使用,为了避免误导大众,这里引用前辈的帖子Android新特性介绍,ConstraintLayout完全解析——
      guolin
      ,请见谅

二、文本控件

文本控件最常用的也就两个,TextViewEditText

  1. TextView,顾名思义就是文本视图,实际上它就是承载字符串的一个视图控件,使用方法如下所示,android:layout_width和android:layout_height一般使用wrap_content来进行自适应宽高,例如android:layout_width="wrap_content"android:layout_height="wrap_content":
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="horizontal">
        <TextView
            android:layout_width="200dp"<!--设置文本控件所占宽度-->
            android:layout_height="200dp"<!--设置文本控件所占高度-->
            android:layout_gravity="center"<!--设置文本控件居于父控件的什么位置-->
            android:background="#FF6143"<!--设置文本控件的背景-->
            android:gravity="center"<!--设置文本居于文本控件的什么位置-->
            android:textColor="@android:color/white"<!--设置文本文字颜色-->
            android:textSize="20sp"<!--设置文本字号大小-->
            android:text="我是TextView" /><!--设置文本文字-->
    </LinearLayout>
    
    效果图
    在这里插入图片描述
  2. EditText,顾名思义就是编辑文本,实际上他就是一个编辑文本框视图控件,它是基于TextView衍生出来的一个控件,就是说TextView有的属性,它也有,TextView没有的属性,它都有。它的使用方法如下:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="horizontal">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="这里可以输入文字"<!--提示文本-->
            android:textColorHint="@android:color/darker_gray"<!--提示文本的颜色-->
            android:inputType="text"/><!--文本输入类型,常用的就是textPassword、number、phone-->
    </LinearLayout>
    
    效果图如下
    在这里插入图片描述
    以下是TextViewEditText结合的一个简单的登录页面的例子
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="16dp">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="用户名:"
                android:textColorHint="@android:color/darker_gray" />
    
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="输入用户名"
                android:inputType="text"
                android:textColorHint="@android:color/darker_gray" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密    码:"
                android:textColorHint="@android:color/darker_gray" />
    
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="输入密码"
                android:inputType="textPassword"
                android:textColorHint="@android:color/darker_gray" />
        </LinearLayout>
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="登录" />
    </LinearLayout>
    
    效果图如下:
    在这里插入图片描述

三、按钮控件

文本控件最常用的也就五个,ButtonImageButtonRadioButtonCheckBoxSwitch

  1. Button,顾名思义就是一个按钮,它也是基于TextView控件衍生出来的一个视图控件,但是它具备触感反馈能力,它的使用方法如下

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="16dp">
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="按钮"/>
    
    </LinearLayout>
    

    效果图
    在这里插入图片描述

  2. ImageButton,顾名思义就是一个图片按钮,但是它是ImageView衍生出来的一个视图控件的,所以他就没有文本属性了,它是用src属性来显示按钮内容的,就是用图片存放到按钮处,大概使用方法如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="16dp">

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher_round"/>

</LinearLayout>

效果图
在这里插入图片描述

  1. RadioButton,顾名思义就是单选按钮,但是它是基于Button二次开发的,它通常需要配合单选组RadioGroup一起使用,因为RadioGroup就是用来约束RadioButton实现单选的,具体使用方法如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="16dp">

    <RadioGroup
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_height="wrap_content">

        <RadioButton
            android:layout_width="wrap_content"
            android:text=""
            android:checked="true"
            android:layout_height="wrap_content" />
        <RadioButton
            android:layout_width="wrap_content"
            android:text=""
            android:layout_height="wrap_content" />
    </RadioGroup>

</LinearLayout>

效果图如下
在这里插入图片描述

  1. CheckBox,顾名思义就是一个选择盒子,它实际上就是一个多选按钮,它也是基于Button二次开发的,它的具体用法如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:padding="16dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="兴趣选择:" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="篮球" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="排球" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="足球" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="羽毛球" />
    </LinearLayout>

</LinearLayout>

效果图
在这里插入图片描述

  1. Switch,顾名思义开关,实际上他就是一个开关控件,它也是基于Button二次开发的,具体使用方法如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:padding="16dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="接收消息推送" />

        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>


</LinearLayout>

效果图如下
在这里插入图片描述

  1. 综合使用例子
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:padding="16dp">
    <!--性别-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="性别:" />

        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="" />
        </RadioGroup>
    </LinearLayout>
    <!--兴趣选择-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="兴趣选择:" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="篮球" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="排球" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="足球" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="羽毛球" />
        </LinearLayout>
    </LinearLayout>
    <!--订阅消息-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="订阅消息:" />

        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true" />
    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="提交修改" />

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:src="@mipmap/ic_update" />
</LinearLayout>

效果图
在这里插入图片描述
上述所有的android:check="true"都是我模拟手动点击的,实际开发可能用不到的,android:src=""这个属性就是保持原图片的尺寸放到对应的图片视图控件里面

四、其他控件

  1. ImageView,顾名思义就是一个图片视图控件,它的具体用法如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:padding="16dp">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher_round" />
</LinearLayout>

效果图
在这里插入图片描述

  1. ScrollView,顾名思义就是一个滑动视图,它的存在就是为了解决控件数量超出了页面可示的数量却又无法滑动显示的窘境,但是它的子视图只能是一个视图,具体用法如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:padding="16dp">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="不是可示区域" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="不是可示区域" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

效果图,右边有一条滑动条
在这里插入图片描述

  1. RecyclerView,它的存在是为了解决ListViewGridView存在的性能以及其他问题,同时它又能提供滑动效果,用法如下

    1. 线性(List方式):
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center_vertical"
          android:orientation="vertical"
          android:padding="16dp">
      
          <android.support.v7.widget.RecyclerView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
      </LinearLayout>
      
    2. 网格(Grid方式)
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center_vertical"
          android:orientation="vertical"
          android:padding="16dp">
      
          <android.support.v7.widget.RecyclerView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layoutManager="android.support.v7.widget.GridLayoutManager"
              app:spanCount="2" />
      </LinearLayout>
      
    3. 瀑布流(Grid方式)
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center_vertical"
          android:orientation="vertical"
          android:padding="16dp">
      
          <android.support.v7.widget.RecyclerView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layoutManager="android.support.v7.widget.StaggeredGridLayoutManager" 
              app:spanCount="2"/>
      </LinearLayout>
      
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目录 第一篇 Android 系统结构和SDK 使用............................................................................................................................ 5 第1 章 Android 的系统介绍........................................................................................................................................... 5 1.1 系统介绍........................................................................................................................................................... 5 1.2 软件结构和使用的工具................................................................................................................................... 7 第2 章 Android SDK 的开发环境.................................................................................................................................. 10 2.1 Android SDK 的结构...................................................................................................................................... 10 2.2 Android SDK 环境安装.................................................................................................................................. 11 2.2.1. 安装JDK 基本Java 环境。................................................................................................................ 11 2.2.2. 安装Eclipse........................................................................................................................................... 12 2.2.3. 获得Android SDK ...............................................................................................................................12 2.2.4(1). 在Eclipse 3.4(Ganymede)中安装ADT............................................................................... 14 2.2.4(2). 在Eclipse 3.5(Galileo)中安装ADT..................................................................................... 17 2.2.5. 在Eclipse 中配置Android SDK ......................................................................................................... 20 2.3 Android 中运行仿真器环境............................................................................................................................ 21 2.3.1. 建立Android 虚拟设备....................................................................................................................... 21 2.3.2. 运行虚拟设备........................................................................................................................................ 22 2.3.3. 使用Android 中的工具....................................................................................................................... 23 2.3.4. 使用logcat............................................................................................................................................. 24 2.3.5. 使用仿真器控制.................................................................................................................................... 25 2.3.6. 命令行工具adb、mksdcard 等.......................................................................................................... 26 2.3.7. 使用设备控制........................................................................................................................................ 28 2.4 Android 中建立工程........................................................................................................................................ 29 2.4.1. 建立工程................................................................................................................................................ 29 2.4.2. 查看和编辑各个文件............................................................................................................................ 31 2.4.3. 运行工程................................................................................................................................................ 33 第二篇 Android 应用程序的概述和框架....................................................................................................................... 36 第3 章 Android 应用层程序的开发方式....................................................................................................................... 36 3.1 应用程序开发的结构....................................................................................................................................... 36 3.2 API 参考文档的使用........................................................................................................................................ 36 第4 章Android 应用程序示例........................................................................................................................................ 40 4.1 HelloActivity 程序的运行............................................................................................................................ 40 4.2 HelloActivity 的源文件结构........................................................................................................................ 41 4.2.1.Android.mk 文件................................................................................................................................. 41 4.2.2.AndroidManifest.xml 文件................................................................................................................. 42 4.2.3.源代码文件........................................................................................................................................... 42 4.2.4.布局文件............................................................................................................................................... 43 4.2.5.其他资源文件....................................................................................................................................... 43 4.3 HelloActivity 的编译结构............................................................................................................................ 43 4.4 SkeletonApp 的程序的运行........................................................................................................................ 44 4.5 SkeletonApp 的源文件结构........................................................................................................................ 44 4.6 SkeletonApp 的编译结构............................................................................................................................ 46 第5 章 Android 应用程序的内容................................................................................................................................... 47 5.1 Android 应用程序的概念性描述................................................................................................................. 47 5.1.1.应用程序的组成部分........................................................................................................................... 47 5.1.2.应用程序的生命周期........................................................................................................................... 48 5.2 应用程序包含的各个文件.............................................................................................................................50 5.3 使用am 工具启动Android 应用程序........................................................................................................ 51 2 第三篇Android 的UI 系统实现..................................................................................................................................... 53 第6 章 UI 的基本外形和控制........................................................................................................................................ 53 6.1 控件和基本事件的响应................................................................................................................................. 53 6.1.1.事件响应方法....................................................................................................................................... 54 6.1.2.第二种响应方法................................................................................................................................... 56 6.1.3.第三种响应方法................................................................................................................................... 57 6.2 键盘事件的响应............................................................................................................................................... 57 6.3 运动事件的处理............................................................................................................................................... 59 6.4 屏幕间的跳转和事件的传递........................................................................................................................... 62 6.4.1.跳转的方法........................................................................................................................................... 62 6.4.2.带有返回值的跳转...............................................................................................................................63 6.5 菜单的使用........................................................................................................................................................ 66 6.6 弹出对话框........................................................................................................................................................ 67 6.6.1. 提示信息和两个按钮的对话框............................................................................................................ 68 6.6.2. 提示信息和三个按钮的对话框............................................................................................................ 69 6.6.3. 列表项对话框........................................................................................................................................ 70 6.6.4. 单选项和按钮对话框............................................................................................................................ 70 6.6.5. 复选项和按钮对话框............................................................................................................................ 71 6.6.6. 文本的按键对话框(使用布局文件)................................................................................................ 72 6.7 样式的设置....................................................................................................................................................... 74 6.7.1.预定样式对话框................................................................................................................................... 74 6.7.2.自定义样式对话框...............................................................................................................................74 6.7.3.窗口透明样式示例...............................................................................................................................75 第7 章控件(Widget)的使用..................................................................................................................................... 78 7.1 Android控件的层次结构......................................................................................................................... 78 7.2 基本控件使用............................................................................................................................................. 79 7.2.1.普通按钮............................................................................................................................................... 79 7.2.2.图像区域............................................................................................................................................... 80 7.2.3.图像按钮............................................................................................................................................... 82 7.2.4.进度条................................................................................................................................................... 83 7.2.5.多种控件............................................................................................................................................... 85 7.3 自定义的视图................................................................................................................................................... 86 第8 章视图组(ViewGroup)和布局(Layout)的使用........................................................................................... 89 8.1 Android 的屏幕元素体系................................................................................................................................ 89 8.2 几种独立使用的视图组................................................................................................................................... 90 8.2.1.网页视图............................................................................................................................................... 90 8.2.2.旋转按钮............................................................................................................................................... 91 8.2.3.文本切换器........................................................................................................................................... 93 8.2.4.图像切换器........................................................................................................................................... 94 8.3 作为简单容器使用的视图组........................................................................................................................... 95 8.3.1.单选按钮组........................................................................................................................................... 95 8.3.2.使用滚动条........................................................................................................................................... 96 8.4 布局(Layout) .............................................................................................................................................. 99 8.4.1.基本的布局内容................................................................................................................................... 99 8.4.2.线性布局(LinearLayout) ............................................................................................................. 100 8.4.3.相对布局(RelativeLayout)........................................................................................................... 101 8.4.4.表单布局(Table Layout).............................................................................................................. 103 8.5 网格(Grid)视图组................................................................................................................................... 103 3 8.6 列表(List)视图组.................................................................................................................................... 107 8.7 使用Tab 组织UI ......................................................................................................................................... 109 第9 章 2D 图形接口的使用......................................................................................................................................... 113 9.1 使用2D 图形接口的程序结构。.................................................................................................................. 113 9.2 图像、图形、文本的基本绘制..................................................................................................................... 114 9.3 文本的对齐方式............................................................................................................................................. 116 9.4 使用路径效果(PathEffect) ..................................................................................................................... 118 9.5 剪裁效果......................................................................................................................................................... 119 9.6 记录绘制的过程............................................................................................................................................. 121 9.7 动画效果......................................................................................................................................................... 123 第10 章 OpenGL 3D 图形的使用................................................................................................................................125 10.1 使用OpenGL 图形接口的程序结构。..................................................................................................... 125 10.2 基本的绘制................................................................................................................................................... 126 10.3 渲染器的实现............................................................................................................................................... 127 10.4 3D 动画效果的实现...................................................................................................................................... 129 4

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值