Android day01
一、android与iOS系统的特点
android | iOS |
---|---|
google公司开发的手机系统 | 苹果公司开发的手机系统 |
任何程序都能在后台运行 | 任何第三方程序都不能在后台运行 |
优先级响应层级是Application–Framework–Library–Kernal架构,显示相关的图形图像处理这一部分属于Library | Ui指令权限最高,对屏幕反应的优先级是最高的 |
采用的是虚拟机运行机制 | 采用沙盒运行机制 |
Android完全开源 | ios完全封源开发 |
Android有很多免费的应用跟应用市场 | ios只有一个应用市场:App Store |
编程语言是Java和KotLin | 编程语言是ObjectC和Swift |
底层建立在Linux系统之上 | 底层建立在UNIX系统之上 |
Android生成class文件,需要虚拟机来进行解释 | ios直接执行程序的二进制代码 |
性能比C语言和OC低 | 基于对象,完全兼容C语言的语法,可以直接操作内存 |
二、编写一个hello word程序
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hello word!"
/>
</LinearLayout>
三、使用Android的五种布局方式来设计一个界面
1.线性布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="线性布局"
/>
</LinearLayout>
2.框架布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="12"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="框架布局" />
</FrameLayout>
</FrameLayout>
3.表格布局
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="12"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="表格布局" />
</TableLayout>
</TableLayout>
4.绝对布局
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="绝对布局"
/>
</AbsoluteLayout>
5.相对布局
<?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:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="12"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="相对布局"
/>
</RelativeLayout>
</RelativeLayout>
四、使用ArrayAdapter的方式实现一个城市选择的下拉列表
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/spinner" />
</LinearLayout>
MainActivety.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner)findViewById(R.id.spinner);
String[] city = new String[]{"北京","上海","广州","深圳"};
ArrayAdapter<String>adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,city);
spinner.setAdapter(adapter);
}
}
五、设计一个登录界面
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:textColor="@color/black"
android:text="手机号:"
android:textSize="20dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:id="@+id/phone"
android:hint="请输入手机号"
android:inputType="phone"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textColor="@color/black"
android:text="密 码:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/password"
android:inputType="numberPassword"
android:hint="请输入密码"
/>
</LinearLayout>
<!-- 提交数据按钮-->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册并查看"
android:id="@+id/submit"
></Button>
MainActivety.java
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
// 定义将要读取的变量
private String str_phone="",str_password="";
// 组件的定义
private EditText phone,password;
private Button submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
innit();
// 绑定数据存储按钮
store.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,storeActivity.class);
startActivity(intent);
}
});
}
private void innit() {
phone = (EditText) findViewById(R.id.phone);
password = (EditText) findViewById(R.id.password);
submit = (Button) findViewById(R.id.submit);
submit.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.submit:
str_phone = phone.getText().toString();
str_password = password.getText().toString();
// 通过Intent切换页面传值
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putString("phone",str_phone);
bundle.putString("password",str_password);
intent.putExtras(bundle);
startActivity(intent);
break;
}
}
}