1. 搭建开发环境

去官网(https://developer.android.google.cn/studio)下载 Android Studio


安装SDK(默认Android 7.0即可)

全局 gradle 镜像配置

在用户主目录下的 .gradle 文件夹下面新建文件 init.gradle,内容为

allprojects {repositories {def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central'def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'all { ArtifactRepository repo ->if(repo instanceof MavenArtifactRepository){def url = repo.url.toString()if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."remove repo}if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."remove repo}}}maven {url ALIYUN_REPOSITORY_URLurl ALIYUN_JCENTER_URL}}buildscript{repositories {def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central'def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'all { ArtifactRepository repo ->if(repo instanceof MavenArtifactRepository){def url = repo.url.toString()if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."remove repo}if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."remove repo}}}maven {url ALIYUN_REPOSITORY_URLurl ALIYUN_JCENTER_URL}}}
}

安装模拟器

2. 生成APK文件

两种方式,一种是debug版本,一种是带签名的版本。

debug版本

带签名的版本


构建完毕后可以在 app/build/outputs/apk里找到


运行结果:

3. 练习线性布局

番外:如何创建一个新的 Activity?

YourName 替换为你要创建的 Activity的名字,点击Finish即可。

orientation

  • vertical(垂直): 从上到下
  • horizontal(水平):从左到右

dp:设置边距单位
sp:设置文字大小单位

尽量避免将宽高设置为固定值。

练习一:试着做出如下界面

实现解析:将整体看作一个大的线型布局(纵向),里面塞三个横向布局。
将文本1,2放入第一个横向布局,文本3放入第二个横向布局,文本4放入第三个横向布局。

<?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"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".LinearActivity"android:orientation="vertical"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="横向排列1" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="横向排列2" /></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="纵向排列1" /></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="纵向排列2" /></LinearLayout></LinearLayout>

效果如图:

在此基础上,使用 marginpaddingtextSizegravitylayout_gravity修饰后的效果:

最终代码:

<?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"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".LinearActivity"android:orientation="vertical"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="20dp"android:text="横向排列1" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="30dp"android:text="横向排列2" /></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="15dp"android:text="纵向排列1" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:padding="10dp"android:text="纵向排列2" /></LinearLayout></LinearLayout>

4. 练习相对布局。

强调相对定位,以其他组件或父容器作为参照物,摆放组件的位置。

  • android:gravity 设置子组件的摆放方式。
  • android:ignoregravity 设置某个子组件不受gravity的控制。

设置组件上的属性:android:layout_aboveandroid:layout_belowandroid:layout_toLeftOfandroid:layout_toRightOf

练习一:实现三个文本对齐,以第一个文本为参照相对定位。

新建一个 Activity,起名为 RelativeActivity


相对布局的操作就是:首先定义一个 RelativeLayout的布局,为其一个子元素赋予属性 android:id(如:@id/text1),其他元素则可以用 android:layout_below="@id/text1"来相对定位。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".RelativeActivity"><TextViewandroid:id="@+id/text1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="文本一"/><TextViewandroid:id="@+id/text2"android:layout_below="@id/text1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="文本二"/><TextViewandroid:layout_below="@id/text2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="文本三"/>
</RelativeLayout>

5. 练习表格布局。

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:shrinkColumns="6"android:collapseColumns="5"tools:context=".TableActivity"><TableRow><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:text="第1列"/><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:text="第2列"/><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:text="第3列"/><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:layout_gravity="center"android:text="第4列"/><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:layout_gravity="center"android:text="第5列"/><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:layout_gravity="center"android:text="第6列"/><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:layout_gravity="center"android:text="第7列asdfmaksjdkifjasdjfkasjdkf j"/></TableRow><TableRow><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:text="第1列"/><TextView android:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:text="第2列"/></TableRow>
</TableLayout>

6. 练习网格布局。

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:columnCount="3"android:rowCount="5"android:orientation="horizontal"tools:context=".layout.GridLayout"><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件1"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件2"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件3"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件4"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件5"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件6"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件7"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件8"android:layout_rowSpan="2"android:layout_gravity="center"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件9"android:textSize="20sp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="组件10"android:layout_column="2"android:textSize="20sp"/>
</GridLayout>

7. 练习约束布局。

魔法棒

《嵌入式应用开发》实验一、开发环境搭建与布局相关推荐

  1. 物联网云平台设计与开发: 实验1 前端环境搭建与开发

    目录 实验目的 实验内容 具体实验步骤 第一步:Node.js安装及环境配置 第二步:环境变量配置. 第三步:全局安装webpack 第四步:vue-cli 脚手架构建工具 第五步:将工程导入Visu ...

  2. Python 网站开发(一)环境搭建

    前些天看到小阳买回来的一本 Python 基础教程,于是就产生了使用 Python 来开发一个小博客的想法.这个 Python 网站开发系列文章将不会过多说 Python 基本语法,主要是面向实践的. ...

  3. 使用Eclipse JEE+Mtj+Nokia S60 V3SDK开发J2ME应用的环境搭建

    使用Eclipse JEE+Mtj+Nokia S60 V3SDK开发J2ME应用的环境搭建 2010-04-07 16:53 在Nokia S60 V3下进行J2ME应用程序开发,需要搭建 Noki ...

  4. 安卓开发(一)环境搭建、基本程序与控件

    layout: post title: 安卓开发(一)环境搭建.基本程序与控件 description: 安卓开发(一)环境搭建.基本程序与控件 tag: 安卓 文章目录 Intent:协助应用间的交 ...

  5. 全志A33开发板vstar编译环境搭建

    全志A33开发板vstar编译环境搭建 安装系统 全志提供的vstar的SDK使用内核linux-3.4.39, 在编译过程中,要用到一个文件gen_check_code,位于linux-3.4/ar ...

  6. 保姆级教程:Linux(Ubuntu 18.04)下VSCode配置与嵌入式开发平台X2000_Halley5调试环境搭建

    保姆级教程:Linux(Ubuntu 18.04)下VSCode配置与嵌入式开发平台X2000_Halley5调试环境搭建 写在前面 配置VSCode的编译环境 配置VSCode的gdb调试环境 配置 ...

  7. linux 国产化 gtk图形界面开发 go和c++环境搭建

    linux 国产化 gtk图形界面开发 go和c++环境搭建 一.c++环境搭建 1.解决系统自带gcc无法编译gtk的问题 sudo apt-get install build-essential ...

  8. 3D打印软件Cura的二次开发(GUI)--环境搭建

    3D打印软件Cura的二次开发(GUI)--环境搭建 软体动物Ai  关注 2016.07.06 12:36*  字数 1639  阅读 1300 评论 8 喜欢 4 本文采用中国大陆版CC协议发布 ...

  9. Java程序设计实验一 Java环境搭建

    实验一   Java环境搭建 一.实验目的及要求 1.实验目的 2.实验要求 二.实验环境 三.实验内容 1.实验方案 2.实验步骤 3.设计思路 四.实验结果与分析 下载jdk 配置环境变量 检测环 ...

  10. eclipse开发cocos2dx 3.2环境搭建之一: Android C\C++环境搭建(ndk r9d)

    这几天有时间,琢磨一下cocos2dx.cocos2d家族其实挺庞大的,也有cocos2d-android这种可以直接用Java语言来开发的,但是cocos2d-android资料相对少一些,而且貌似 ...

最新文章

  1. 例题3-5 生成元(Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
  2. 制定和实施网络安全事件响应计划(1)
  3. TCP-Z V2.6.2 Build 20090409 (半开连接数监控与破解)
  4. platform_driver_probe与platform_driver_register的区别
  5. Git:add多个文件或者目录的方式
  6. Jnotify文件监控的用法以及Jar文件导入的方法
  7. yagmail和keyring的安装与注册
  8. UG二次开发入门--一个简单的示例
  9. PS教程 | 美女面部剥落碎片效果
  10. OpenGL的安装(GLFW+GLAD)
  11. 计算机无法完成评估,window_Windows Vista下系统评分无法完成的问题,不知道大家有没有遇到过这样 - phpStudy...
  12. Python之绘制个人足迹地图
  13. 前端三刺客---CSS
  14. 硬核科普!关于5G辐射,你了解多少!
  15. html页面日期显示带0,XHTML1.0与HTML兼容指引16条 小结
  16. 极客时间 资源_极客学校:学习Windows 7 –资源访问
  17. 如何使用AD账号登录腾讯企业邮箱?
  18. Un-Routed Net ConStraint报错的原因
  19. Office VBA开发经典-基础入门卷 配套资源下载
  20. php mysql 撮合交易_Php+Redis 币币交易撮合

热门文章

  1. 可转债第一课:神奇的可转债
  2. skywalking源码分析第十八篇一agent端Trace三部曲一Span栈桢机制
  3. Kotlin 协程与flow
  4. sicily 1140 国王的遗产
  5. Excel怎样把相同列数据合并到一行
  6. Linux Shell 编程语法
  7. 机器视觉之缺陷检测的光源
  8. 偏微分方程的特征线法
  9. LeetCode 11-20 题
  10. 字符串、列表、字典、元组的基本操作