20175201张驰 实验四 Android 开发

4-1:【Android Studio安装】安装过程中出现的错误:参考https://blog.csdn.net/weixin_38277423/article/details/80254483

1.The SDK location is in inside studio install location
错误描述:The SDK location is in inside studio install location
解决方法:这个是由于SDK的安装目录是在Android Studio(简称:AS)的安装目录下,所以只需要在AS的安装目录外新建一个文件夹,并把SDK指定到这个目录下即可。
示例:AS 安装目录为-- D:\android-studio,只要SDK指定在这个目录外就可以了。

2.Android sdk location should not contain whitespace
解决方法:SDK的目录名称不能有空格。

3.图片.png

原因:
在第一次安装AS,启动后,检测到电脑没有SDK。

知道了原因,自然有解决方法,可以在以后安装sdk,或者设置初次打开AS,不下载sdk

解决方法:
第一种:
点击Cancel,在后续的界面再安装SDK。
图片.png
图片.png

第二种:设置初次打开AS,不下载sdk
1、在这个Android studio的安装目录下,找到下面这个文件: \bin\idea.properties
2、设置初次打开AS,不检测SDK。使用记事本打开,文件末尾添加一行:
  disable.android.first.run=true
网上大部分介绍这种方法,但是治标不治本,SDK没有下载,就算进入界面了,也用不了。还是要去下载SDK。
安装完成Android Studio
1.png

创建项目:
红色方框选中的Start a new Android Studio project选项通常是我们课程里最常使用的,用于创建一个新的Android项目。
在此介绍一下其他的选项:
Open an existing Android Studio Project:打开已有的Android Studio项目。在经历一段时间的学习后,如果你想继续编辑之前的项目,或者打开一个从网上下载的例子,你可以点击此选项。
Check out project from Version Control:从版本控制库中获取项目。对于团队开发来说,版本控制是必不可少的工具。此选项允许你从GitHub、Google Cloud以及TortoiseSVN等处同步项目。事实上,Android Studio对于这些版本控制工具的支持也是很好的,你可以在设置中进行设定。
Import project(Eclipse ADT, Gradle, etc.):导入其他开发环境中的项目。通过该选项你可以将在Eclipse等处生成的项目迁移到Android Studio的开发环境中。
Import an Android code sample:导入Android代码样例。该功能将从Google及其合作伙伴那里读取示例的列表,你可以下载并查看一些优秀的项目并继续编辑它们。

2.png
3.png

更改acitvity_main.xml 中的代码:

4.png
5.png

4-2:
实验要求:

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:
构建项目,运行教材相关代码
创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

步骤:
1.png
2.png
1.MainActivity:

package com.besti.is.zc.secondactivitydemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this,ThirdActivity.class);
startActivity(intent);
}
}
2.左上角file->new->Activity->empty Activity创建ThirdActicity

3.png
3.activity_main.xml

<android.support.constraint.ConstraintLayout 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="wyhy.activity.MainActivity">

</android.support.constraint.ConstraintLayout>

4.activity_third.xml

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

</android.support.constraint.ConstraintLayout>

运行截图:
5.png
4-3:UI测试

实验要求

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:
构建项目,运行教材相关代码
修改代码让Toast消息中显示自己的学号信息
提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

步骤:

1.Main_Activity

package com.besti.is.zc.ui;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(this,"20175201,Toast.LENGTH_LONG).show();
}
}

2.activity_main.xml

<android.support.constraint.ConstraintLayout 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="wyhy.ui.MainActivity">

</android.support.constraint.ConstraintLayout>
运行截图:
92e9c5dfed3e51a23867588f8b69661.png
布局测试

实验要求
-参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:

构建项目,运行教材相关代码
修改布局让P290页的界面与教材不同
提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

步骤:
1.activity_main.xml

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="2dp"
android:paddingRight="2dp">

posted @ 2019-05-14 16:39  20175201张驰  阅读(403)  评论(0)    收藏  举报