Android day01

Android day01

一、android与iOS系统的特点

androidiOS
google公司开发的手机系统苹果公司开发的手机系统
任何程序都能在后台运行任何第三方程序都不能在后台运行
优先级响应层级是Application–Framework–Library–Kernal架构,显示相关的图形图像处理这一部分属于LibraryUi指令权限最高,对屏幕反应的优先级是最高的
采用的是虚拟机运行机制采用沙盒运行机制
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;
        }

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@小玉同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值