2017Google Study Jams之L1Android

2017-03-19  本文已影响245人  Shawpoo的

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

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

Google Developers

通过前面对View和ViewGroup的认识,相信你对基本的控件(TextView, ImageView, Button等)和简单的布局(LinearLayout,RelativeLayout)有了一定了解,此时此刻你一定也想自己动手敲一下,敲出自己的第一行代码,运行出自己的第一个程序。

本笔记主要记录和介绍Android开发环境的搭建和运行出第一行代码以及生日贺卡的实现。

一、环境的搭建

1、JDK的安装

A、安装JDK

选择JDK的版本 同意并下载JDK 安装JDK 安装JDK 安装JDK 安装JDK

B、JDK环境变量的配置

配置JDK环境变量 配置环境变量2.png 配置环境变量 配置环境变量 环境变量的配置 配置环境变量 验证环境换量

2、Android Studio的安装

首先我们需要下载Android Studio安装包,这里推荐两种方式下载

由于我的电脑已经装有Android Studio了,所以就不重复安装了,这里推荐两个网上的安装教程,教程1教程2

安装成功之后就是这样:

安装完成

二、开始Android的第一行代码以及制作生日贺卡

在上面介绍了环境的安装之后,开始使用Android Studio创建第一个项目。

开始创建项目 填写项目名称,选择创建目录 设置SDK版本 选择Activity的模板 为主页面命名 创建项目成功 运行结果

好了,项目建好并运行了在手机上的第一个应用程序,接下来该制作一个生日贺卡了。结合之前学习的View和ViewGroup进行实操。

由于这次的生日贺卡知识针对之前学习的内容进行回顾,所以Activity中没有什么逻辑体现,只是通过控件和布局的配合实现简单的生日贺卡页面。所以直接呈上布局的代码:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#1F1A17"
    android:padding="@dimen/activity_horizontal_margin"
    tools:context="com.shawpoo.app.MainActivity">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="To:Study Jams"
        android:textColor="@android:color/white"
        android:typeface="serif"
        android:textSize="35sp"/>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@mipmap/img_happy_birthday"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="From:Mr.W"
        android:typeface="serif"
        android:textColor="@android:color/white"
        android:textSize="35sp"/>
</RelativeLayout>

我采用的根布局是相对布局,所以只需要对内部的View进行一个位置的控制即可,所以"To:Study Jams"放在左上角,由于相对布局默认出现的控件就在左上角,所以关于位置不需要任何属性,贺卡的图片是通过“android:layout_centerInParent”属性放在布局的中间,"From:Mr.W"是放在布局的最后边和最下边,对应的布局是“android:layout_alignParentRight”和“android:layout_alignParentBottom”,这样一个简单的贺卡页面就实现了。

最后来看一下效果图:

生日贺卡效果图
上一篇 下一篇

猜你喜欢

热点阅读