此次活动的举办方:Google Study Jams活动官网

我的博客(同步此次活动笔记):CSDN博客、我的简书

一、1A 认识View的笔记

1、初识Android

  • Android是一款开源的基于Linux的操作系统,主要用于移动设备(手机和平板),也用于汽车,家电等设备上来进入物联网时代。
  • 开发的硬件设备:Windows,Mac等
  • 开发的操作系统:Windows,Linux,Ubuntu等
  • 测试设备:Android手机、平板或其他Android系统设备
  • 集成开发环境:IDE(Android studio(推荐), Eclipse(Google目前不再维护更新))
  • Android Studio:Android Studio 是一个Android集成开发工具,基于IntelliJ IDEA。Android Studio 提供了集成的 Android 开发工具用于开发和调试。
  • 国内比较好的一个中文镜像网站

2、认识Android的View(视图)

  • View:View是屏幕上的一个矩形区域,是布局组件的基本组成元素。
  • Layout:所有的View视图拼起来就是屏幕上的Layout。
  • View有TextView(文本视图),ImageView(图像视图), Button(按钮)等。

3、认识XML

  • 使用Android studio来编写并预览
  • 编写屏幕上的layout,layout由之前认识的View组成
  • XML:Extensible Markup Language 可拓展标记语言,用来编写布局Layout
  • View的命名规则:采用驼峰规则(Camel-Case),也就是将每个单词的首字母大写,中间不加任何符号和空格
  • 标签:双标签或者自闭标签(例: 或)
  • 属性:“=”左边是属性名,右变属性值,每个属性都有默认值
  • 一个在线的视图预览工具

4、开启View的第一个控件:TextView(文本视图)

<TextViewandroid:id="@+id/title_text_view"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/my_photos"android:textAppearance="?android:textAppearanceLarge"android:textColor="#4689C8"android:textStyle="bold" />
  • 单位:

    • dp:用于设置控件的宽高 (与手机像素密度无关)
    • sp:用于设置文本字体的大小 (与手机像素密度无关)
    • px :与手机像素有关(不推荐作为控件的宽高)
  • wrap_content:根据内容的大小决定控件的大小
  • android:textAppearance=”?android:textAppearanceLarge” 可以设置系统的属性,采用大中小字体样式
  • 颜色:引用系统或者本地资源(@color/white)或者采用16进制“#FFFFFF”
  • Common Android Views 常用基础控件模板供参考使用

5、ImageView (图像视图)

<ImageView
      android:id="@+id/photo_image_view"android:layout_width="match_parent"android:layout_height="match_parent"android:src="@drawable/icon"android:scaleType="centerCrop"/>
  • android:src:加载本地图片资源(Android studio对图片资源有一定的要求,建议使用.png的文件资源)
  • android:scaleType:对图片进行一定的裁剪,缩放和位置摆放的操作

6、通过看Android开发文档帮助开发

  • https://developer.android.com/index.html Android开发官网,有Android的API,APP的开发介绍,Material Design语言的介绍等,供开发者查阅学习。

二、1B 认识ViewGroup的笔记

1、认识ViewGroup

  • ViewGroup相当于一个放置View的容器,并且我们在写布局xml的时候,会告诉容器(凡是以layout为开头的属性,都是为用于告诉容器的),例如宽度(layout_width)、高度(layout_height)、对齐方式(layout_gravity)等;当然还有后面要说的layout_margin、layout_padding等;所以一个ViewGroup是一个可以包含子View的容器,是布局文件和View容器的基类。

2、初识布局(Layout)-线性布局(LinearLayout)

  • 水平布局 horizontal
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><Button
            android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮1"/>   <Button
            android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮2"/>   <Button
            android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮3"/>
</LinearLayout>
  • 垂直布局 horizontal
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><Button
            android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮1"/>   <Button
            android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮2"/>   <Button
            android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮3"/>
</LinearLayout>
  • 两种方式效果对比

  • 概念: LinearLayout是线性布局控件,它包含的子控件将以横向或竖向的方式排列。
  • 属性:android:gravity:指定如何在该对象中放置此对象的内容(x/y坐标值)
    android:orientation:设置它内容的对其方向(横向/竖向)
    ps:gravity :这个英文单词是重心的意思,在这里就表示停靠位置的意思。

    • 当 android:orientation=”vertical” 时, 只有水平方向的设置才起作用,垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。
    • 当 android:orientation=”horizontal” 时, 只有垂直方向的设置才起作用,水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。
  • 延伸:android:layout_gravity 和 android:gravity 的区别
    从名字上可以看到,android:gravity是对元素本身说的,元素本身的文本显示在什么地方靠着换个属性设置,不过不设置默认是在左侧的。
    android:layout_gravity是相对与它的父元素说的,说明元素显示在父元素的什么位置。 比如说button: android:layout_gravity 表示按钮在界面上的位置。 android:gravity表示button上的字在button上的位置。

    • 可选值 :
      这两个属性可选的值有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。

3、相对布局(RelativeLayout)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageView
        android:id="@+id/image_center"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:src="@mipmap/ic_launcher"/><Button
        android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toLeftOf="@id/image_center"android:text="我在左边"/><Button
        android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_above="@id/image_center"android:text="我在上边"/><Button
        android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toRightOf="@id/image_center"android:text="我在右边"/><Button
        android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_below="@id/image_center"android:text="我在下边"/>
</RelativeLayout>
  • 概念:RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定)。每个视图的位置能够指定它相对于兄弟(比如在其他视图的左边或是下边)或是父视图(这里是指相对布局容器,比如底部对齐、中间偏左)的位置。
  • 属性:
    • android:layout_toLeftOf:位于相对控件的左方
    • android:layout_above:位于相对控件的上方
    • android:layout_toRightOf:位于相对控件的右方
    • android:layout_below:位于相对控件的下方
    • android:layout_centerVertical:在父布局中垂直居中
    • android:layout_centerHorizontal:在父布局中水平居中
    • android:layout_centerInParent:在父布局正中

4、优化布局-设定布局的内外边距(Paddding、Margin)

  • 简单概述:

    • android:layout_margin就是设置view的上下左右边框的额外空间
    • android:padding是设置内容相对view的边框的距离。
      通俗来说,一个设置内边距,一个设置外边距。
  • ps:在LinearLayout、RelativeLayout、TableLayout中,这2个属性都是设置都是有效的
    在FrameLayout中,android:layout_margin是无效的,因为FrameLayout里面的元素都是从左上角开始绘制的在AbsoluteLayout中,没有android:layout_margin属性。

OK,关于View和ViewGroup的认识就记到这里了。感觉各位的阅读!

2017Google Study Jams之1A对View和ViewGroup的认识相关推荐

  1. 2017Google Study Jams之L1Android Studio的安装与生日贺卡的实现

    此次活动的举办方:Google Study Jams活动官网 我的博客(同步此次活动笔记):CSDN博客.我的简书 通过前面对View和ViewGroup的认识,相信你对基本的控件(TextView, ...

  2. Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...

    UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...

  3. 【Android 应用开发】自定义View 和 ViewGroup

    一. 自定义View介绍 自定义View时, 继承View基类, 并实现其中的一些方法. (1) ~ (2) 方法与构造相关 (3) ~ (5) 方法与组件大小位置相关 (6) ~ (9) 方法与触摸 ...

  4. View和ViewGroup常用方法

    2019独角兽企业重金招聘Python工程师标准>>> Android的UI界面都是由View和ViewGroup及其派生类组合而成的. 其中,View是所有UI组件的基类,而 Vi ...

  5. 精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...

    标题图 UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个 ...

  6. Android(四)——View和ViewGroup

    文章目录 1. 用户界面概述 2. View类常用属性 3. ViewGroup类 4. UI组件的层次结构 1. 用户界面概述 在Android APP中,所有的用户界面元素都是由View和View ...

  7. View和ViewGroup的层次关系

    Layout也是一种View Widget - View Layout - ViewGroup

  8. android应用的界面编程----View与ViewGroup的概念

    1 UI OverView Android中所有的UI元素都是通过View与ViewGroup来构建的,View是指屏幕中一块可与用户进行交互的空白,类似于java界面编程中的JPanel.为了界面布 ...

  9. Android 应用开发(35)---View与ViewGroup的概念

    View与ViewGroup的概念 告别了第一章,迎来第二章--Android中的UI(User Interface)组件的详解, 而本节我们要学习的是所有控件的父类View和ViewGroup类!突 ...

最新文章

  1. 快讯 | 百度发布Apollo1.5 开放五大核心能力,未来3年花100亿投资100家公司
  2. python【蓝桥杯vip练习题库】ADV-306输出三个整数的最大数
  3. Python的random
  4. Spring 整合 aspectj 框架实现的 aop
  5. mac下修改mysql默认字符集为utf8
  6. 关于Storm Tick
  7. 程序实践:命令行之连连看
  8. 接收请求参数及数据回显 2021-04-26
  9. Spring8中lambda表达式的学习(Function接口、BiFunction接口、Consumer接口)
  10. Spring AOP实现原理简介
  11. matlab 信道容量的迭代算法,实验二一般信道容量迭代算法详解.ppt
  12. java计算机毕业设计桂林恒保健康防护有限公司官网MyBatis+系统+LW文档+源码+调试部署
  13. 【比赛报告】2018.10.11校赛[8-2情人节欢乐赛] NOIP练习赛卷十二
  14. linux常用的简单命令(三)tar、scp、df/du、ps、free、top、netstat、tcpdump、kill、reboot/halt/poweroff、shutdown
  15. 链游Farmers World【农民世界】爆火,发布一个免费开源的辅助挂机脚本
  16. linux交叉编译nss3,nspr
  17. 电脑无法识别u盘怎么办
  18. 最好用的手机投屏软件有哪些
  19. 数据结构 - 树的分类
  20. zabbix_进阶使用

热门文章

  1. 机房预约管理系统(c++完整实现)
  2. mac下chrome全屏地址栏不见的解决方法
  3. 计算机问题求解之递归 ※
  4. java radiogroup_android RadioGroup实现单选以及默认选中 | 学步园
  5. MySql安装、启动与停止、进入与退出操作步骤
  6. latex极限符号怎么打_LaTeX常用篇(二)---上下标/分式/根式/求和/连乘/极限/积分/希腊字母...
  7. usb音频传输的优劣
  8. ToString的用法
  9. Python 文件复制
  10. linux云服务器怎么选配?如何配置linux云服务器