一。环境与安卓SDK
java -version
gradle -v
android -h 这个是android sdk,可不下载,用Android Studio创建项目会提示下载
安卓环境变量的配置(打开Android Studio会自动提示下载Android SDK)
D:\android-sdk\tools
D:\android-sdk\platform-tools
D:\android-sdk\build-tools\31.0.0
下面是安卓SDK列表
二。创建项目与运行项目
1、创建项目
用android-studio创建项目 file——new——new project——选择activity—
2、运行项目
1.先配置安卓虚拟设备(点击AVD Manager-create virtual device 新建设备1 设备2)
2.选择好设备点击debug按钮运行项目
三。项目结构(使用android studio)
四。主要文件
多个Java文件——>AndroidManifest.xml一个配置文件——Layout.xml多个布局文件
1.新建Java文件:new——Activity,
2.Activity注册配置,新建会自动在AndroidManifest.xml多出一个activity,默认初始化的activity: <intent-filter></>
3.Activity设置布局:setContentView(R.layout.activity_main2);
五。Gradle
1.三个gradle文件:
setting.gradle(项目): 哪些module应该加入编译过程
build.gradle:应用到所有项目
build.gradle(Module):当前module自己的配置
2.gradle中的配置
miniSdkVersion:最小SDK版本(不指明默认为1,兼容所有的安卓设备) 并不是直接使用版本1就省事,因为有些依赖包需要高版本的SDK
compileSdkVersion:编译时的SDK版本
targetSDKVersion:目标版本
dependencies:依赖库
2.远程仓库地址
buildscript {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}
六。布局
1.什么是布局
简单讲就是对于界面的设计
2.布局的种类
线性布局(LinearLayout):控件位置和代码顺序相关联
相对布局(RelativeLayout):空间位置和代码顺序不关联
桢布局(FrameLayout)
表格布局(TableLayout)
网格布局(GridLayout)
约束布局(ConstraintLaout)
3.画布局
java代码方式
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
//1.创建线性布局
LinearLayout linearLayout = new LinearLayout(this);
//2.设置宽高
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
//3.背景设为红色
linearLayout.setBackgroundColor(Color.RED);
//4.指定此activity的布局
setContentView(linearLayout);
}
xml方式
new——Layout Resource File——填写file name,Root element
4.布局重要属性,在布局xml文件(linearlayout_test)
宽度 android:layout_width="match_parent"
高度 android:layout_height="match_parent"
外边距 android:layout_margin="20dp"
内边距 android:layout_padding="20dp"
方向 android:orientation="vertical" //水平和垂直 horizontal,控件或者文本横着放还是换行放
权重
重力
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
七。控件(在安卓里面控件叫view)
TextView: 文本框
Button: 按钮
ImageView: 处理图片
EditView: 编辑框
Progressbar:进度条