——*Android Studio 开发环境设置——

- 创建安卓应用

  • 首先新建安卓项目

android开发 页面布局 安卓开发设置页面_android

  • 选择基于Empty Activity的模板
  • android开发 页面布局 安卓开发设置页面_线性布局_02

  • 配置项目基本信息
    单击【Finish】按钮
  • android开发 页面布局 安卓开发设置页面_android_03


  • android开发 页面布局 安卓开发设置页面_android_04

  • 点击工具栏上的绿色按钮运行
  • android开发 页面布局 安卓开发设置页面_android开发 页面布局_05

  • 启动模拟器,查看程序运行结果可以看到屏幕正中央有一个标签 - Hello World
  • android开发 页面布局 安卓开发设置页面_android_06

- 修改标签文本属性

  • 这里打开res\layout目录,打开主布局文件activity_main.xml,默认视图Design
  • android开发 页面布局 安卓开发设置页面_android开发 页面布局_07

  • 切换到Code视图
  • android开发 页面布局 安卓开发设置页面_android studio_08

  • 这里我们修改android:text属性值
  • android开发 页面布局 安卓开发设置页面_android开发 页面布局_09

  • 点击绿色运行按钮重新运行,查看效果
  • android开发 页面布局 安卓开发设置页面_android studio_10

  • 看屏幕提示,建议不使用硬编码字符串(hardcoded string),应该使用@string资源,也就是说应该定义字符串变量
  • android开发 页面布局 安卓开发设置页面_线性布局_11

  • 这里在res/values下的strings.xml文件中定义一个字符串变量 welcome
  • android开发 页面布局 安卓开发设置页面_android_12

  • 在布局配置文件activity_main.xml里调用该字符串变量 welcome
  • android开发 页面布局 安卓开发设置页面_android开发 页面布局_13

  • 重新启动应用,查看效果
  • android开发 页面布局 安卓开发设置页面_线性布局_14

- 设置标签字号和颜色

  • 这里要修改标签字号和颜色,用到 textSize - 文本字号;textColor - 文本颜色

、- 重新启动应用,查看效果

android开发 页面布局 安卓开发设置页面_android开发 页面布局_15

- 修改应用程序标题

  • 在应用列表里找到我们创建的安卓应用 - Test
  • android开发 页面布局 安卓开发设置页面_android_16

  • 程序运行,活动栏上的标题是应用程序的名称 - Test
  • android开发 页面布局 安卓开发设置页面_线性布局_17

  • 这里我们需要在字符串资源文件里修改字符串变量app_name的值
  • android开发 页面布局 安卓开发设置页面_android studio_18

重新启动应用,查看效果

android开发 页面布局 安卓开发设置页面_android studio_19

  • 关闭应用,查看应用列表

- 修改主布局并设置布局属性

  • 将约束布局改成线性布局,这里需要将ConstraintLayout改成LinearLayout

- 设置线性布局属性

设置背景图片

官方文档:普通图片放在drawable目录,icon图标放在mipmap目录
drawable: For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe
Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). 
See the Drawable resource type. mipmap: For app launcher icons. The Android system retains 
the resources in this folder (and density-specific folders such as mipmap-xxxhdpi) regardless of 
the screen resolution of the device where your app is installed. This behavior allows launcher 
apps to pick the best resolution icon for your app to display on the home screen. For more 
2information about using the mipmap folders, seeManaging Launcher Icons as mipmap Resources

原文链接:

  • 这里可以把自己想要的背景图片以background.jpg的名字放到到drawable目录里
  • android开发 页面布局 安卓开发设置页面_android studio_20

  • 设置线性布局的background属性
  • android开发 页面布局 安卓开发设置页面_android_21

  • 重新运行程序,查看结果
  • android开发 页面布局 安卓开发设置页面_android studio_22

- 设置子控件对齐方式

  • 设置线性布局的gravity属性为center
  • android开发 页面布局 安卓开发设置页面_android studio_23

  • 重新运行程序,查看结果
  • android开发 页面布局 安卓开发设置页面_android studio_24

- 设置线性布局方向

  • 如果要在线性布局里添加多个标签控件,默认的情况是水平排列,即线性布局的orientation属性默认是horizontal。如果要垂直排列,那么线性布局的orientation属性要设置vertical。
  • android开发 页面布局 安卓开发设置页面_android_25

  • 再添加一个标签,设置其相关属性
  • android开发 页面布局 安卓开发设置页面_ide_26

  • 重新运行程序,查看结果
  • android开发 页面布局 安卓开发设置页面_ide_27

  • 如果想要这两个标签有间距,可设置外边距属性(marginLeft、marginRight、marginTop、marginBottom)
  • android开发 页面布局 安卓开发设置页面_android_28

- 线性布局嵌套示意图

  • 我们还通过布局嵌套实现更多较为复杂的界面,灵活应用于多种场景

- 上机操作

形式:单独完成
题目:创建安卓应用,显示学生信息
要求:设置窗口标题 - “显示学生信息”,分行显示学生信息,包括学号、姓名、性别、年龄、专业、班级、
电话和爱好等信息。

android开发 页面布局 安卓开发设置页面_android_29