The article is too long, it is recommended to read it again!
I like it.
The first step is to open android studio
Step 2: Create an empty Activity
Step 3: Configure the project
Project name (name): Don't you know what project you have? Unknowingly pull out and whip the corpse
Packages name naming rules: (Ignore my naming rules here)
一般命名规则:
com.公司名.项目名.模块名....
对于个人项目,分为:
1.individual(个体):
指个体项目,由个人发起,但非个人独立完成,可公开或私有项目,版权属于发起人
形式:indi.发起者名.项目名.模块名....
2.personal (个人私人):
指个人项目,由个人发起,并独立完成,可分享的项目,版权属于个人
形式:pers.个人.项目名.模块名....
3.private(私人):
指私有项目,由个人发起并独立完成,不用于分享的非公开项目,版权属于个人
形式:priv.个人.项目名.模块名....
SaveLocation (Save project address):
Generally create one: workspace directory storage
Language
In terms of language, I chose kotlin here. After all, it is the official language recommended by Google, and it is also a trend in the future. Of course Java can't be left behind.
This project will support instant apps:
With this check, the app generated in this project can be directly linked to other apps through appLink.
Use AndroidX artifacts:
Use AndroidX API support library. This needs to be checked, otherwise many errors will be reported when using the previous support packages. The latest Android Studio is checked by default. AndroidX is an upgrade to the Android Support Library. The package names of the APIs in the Android Support Library are under android.support.*, and the package names of all APIs in the AndroidX library are under androidx.*. Android Support Library has some APIs that support versions before 4.0. But now most machines are version 4.0 or later, so you can use the new AndroidX API support library, and existing applications only need to modify the package path.
Click the Run button in the upper right corner, the virtual machine is not found and needs to be created.
Select this icon
here and click Creat New Virtual Device
Here is to choose the model you need
Here to choose the system version of the phone, I chose the latest android 10.0
Finally, you can give your device a name, finish.
I usually create a new Activity like this because I am lazy. . . No need to configure
What does it mean to check Generate Layout File?
Indicates that a corresponding layout file will be automatically created for FirstActivity.
What does it mean to check Launcher Activity?
Indicates that FirstActivity will be automatically set as the main activity of the current project.
Just finish directly.
Andriod layout management details (1)-LinearLayout linear layout
*Andriod has 6 layout methods, namely LinearLayout
(linear layout), TableLayout
(table layout), FrameLayout
(frame layout), RelativeLayout
(relative layout), GridLayout
(grid layout) and AbsoluteLayout
(absolute layout).
Introduction to common attributes of LinearLayout
Attribute 1: android:orientation
Specify the direction of the linear layout (horizontal or vertical)
Property 2: android:width
The width of the container in the linear layout
Property 3: android:height
The height of the container in the linear layout
Property 4: android:background
The background of linear layout
Property 5: In android:gravity
linear layout, the position of the child container relative to the parent container
1 attribute value:
android:orientation="horizontal" 指定线性布局方向:水平
android:orientation="vertical" 指定线性布局方向:垂直
2. Attribute value:
android:width="xxxdp"
指定线性布局的容器宽度为:xxxdp
android:width="wrap_content"
指定线性布局的容器宽度为:根据容器内容宽度大小来填充屏幕宽度
android:width="match_parent"
指定线性布局的容器宽度为:撑满整个屏幕宽度
3. Attribute value:
android:height="xxxdp"
指定线性布局的容器高度为:xxxdp
android:height="wrap_content"
指定线性布局的容器高度为:根据容器内容高度大小来填充屏幕高度
android:height="match_parent"
指定线性布局的容器高度为:撑满整个屏幕高度
4. Attribute value:
android:background="#000"
指定线性布局的背景为:黑色(rgb颜色)
android:background="@android:color/black"
指定线性布局的背景为:黑色(引用android系统自带的原始黑色)
andrid:backgrund="@color/colorPrimary"
指定线性布局的背景为:(根据res/color.xml 中的colorPrimary所定义的颜色设置)
5 attribute value:
android:gravity="center"
指定线性布局中,子容器相对于父容器所在的位置为:正中心
android:gravity="cente_verticalr"
指定线性布局中,子容器相对于父容器所在的位置为:垂直方向的正中心
android:gravity="center_horizontal"
指定线性布局中,子容器相对于父容器所在的位置为:水平方向的正中心
android:gravity="left"
指定线性布局中,子容器相对于父容器所在的位置为:最左边(默认)
android:gravity="right"
指定线性布局中,子容器相对于父容器所在的位置为:最右边
android:gravity="top"
指定线性布局中,子容器相对于父容器所在的位置为:最上方(默认)
android:gravity="bottom"
指定线性布局中,子容器相对于父容器所在的位置为:最下方
Vertical direction:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn1"
android:textAllCaps="false" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn2"
android:textAllCaps="false" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn3"
android:textAllCaps="false" />
</LinearLayout>
horizontal direction:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="horizontal">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn1"
android:textAllCaps="false" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn2"
android:textAllCaps="false" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn3"
android:textAllCaps="false" />
</LinearLayout>
Linear direction: horizontal, the position of the control in the vertical direction can be changed by the value of the android:layout_gravity attribute of the control
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="horizontal">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="btn1"
android:textAllCaps="false" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="btn2"
android:textAllCaps="false" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="btn3"
android:textAllCaps="false" />
</LinearLayout>
Linear direction: horizontal. Set the weight ratio between the control and the control by setting the android:layout_weight property of the control. Here, the width ratio between the EditText control and the Button control is set to 1:1. The premise is that you must first Set the android:layout_width="0dp" of these two controls.
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/et1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Type something" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="send"
android:textAllCaps="false" />
</LinearLayout>
If only the EditText control
android:layout_width=“0dp”
android:layout_weight=“1”
And the Button control
android:layout_width="wrap_content“”
android:layout_weight attribute is not set (note that it is not set here)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/et1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Type something" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"
android:textAllCaps="false" />
</LinearLayout>
Understanding of android:id="@+id/xx"
@+id/height The
"@" symbol is a reminder that the XML parser should parse the following string into an identifier.
The "+" symbol means that an identification symbol will be added.
"Id/" means that this identifier is classified under "id".
"Height" is the main "android:id" of this interface.
In future procedures, "R.id.height" will be used to obtain this interface component. Therefore, "@+id/height" means that we have created an identifier named "height" here, which can be used to control the corresponding interface components, and the "R" class will automatically configure an address for this interface Components. The content of the "R" class can be found by viewing the "R.java" file.
Have you finished watching? ? ? ? ?