当前位置:   article > 正文

Android开发学习笔记整理(6)-homework1讲解_安卓开发学习笔记

安卓开发学习笔记

代码部分:

part1:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/panda"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"/>

    <EditText
        android:id="@+id/phone"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:ems="10"
        android:inputType="phone"
        android:layout_below="@+id/logo"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:hint="请输入手机号"
        android:background="@drawable/input_shape"
        android:paddingLeft="15dp"/>

    <LinearLayout
        android:id="@+id/passwordLayout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/phone"
        android:layout_marginTop="20dp"
        android:layout_alignLeft="@+id/phone"
        android:layout_alignRight="@+id/phone"
        android:background="@drawable/input_shape">

        <!-- 宽度设置0dp √ 由于权重设置为1 -->
        <EditText
            android:id="@+id/password"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="textPassword"
            android:hint="请输入密码"
            android:paddingLeft="15dp"
            android:background="@null"/>

        <!-- gravity相对于父容器排列 -->
        <View
            android:layout_width="1dp"
            android:layout_height="25dp"
            android:background="@color/inputColor"
            android:layout_gravity="center_vertical"></View>

        <Button
            android:id="@+id/forgetButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="忘记密码"
            android:textColor="@color/inputColor"
            android:textSize="16sp"
            android:background="@null"></Button>
        
    </LinearLayout>

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:text="登          录"
        android:textColor="#FFFFFF"
        android:layout_below="@+id/passwordLayout"
        android:layout_marginTop="30dp"
        android:layout_alignLeft="@+id/passwordLayout"
        android:layout_alignRight="@+id/passwordLayout"
        android:background="@drawable/button_shape"/>

    <Button
        android:id="@+id/registerButton"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:text="注册账号"
        android:textColor="@color/colorPrimary"
        android:background="@null"
        android:layout_below="@+id/loginButton"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
效果图:

在这里插入图片描述

input_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <stroke android:width="1dp" android:color="@color/inputColor"></stroke>

    <corners android:radius="8dp"></corners>

</shape>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
效果图:

在这里插入图片描述

button_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="8dp"></corners>

    <solid android:color="@color/colorPrimary"></solid>

</shape>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
效果图:

在这里插入图片描述

panda.png

在这里插入图片描述

part2:

activity_forget.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/phoneLayout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="40dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/input_shape">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="+86"
            android:textSize="16sp"
            android:gravity="center_vertical"
            android:paddingLeft="15dp"
            android:paddingRight="10dp"/>

        <View
            android:layout_width="1dp"
            android:layout_height="25dp"
            android:background="@color/inputColor"
            android:layout_gravity="center_vertical"></View>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@null"
            android:hint="请输入手机号"
            android:paddingLeft="10dp"
            android:inputType="phone"></EditText>

    </LinearLayout>

    <Button
        android:id="@+id/nextButton"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_below="@id/phoneLayout"
        android:layout_marginTop="30dp"
        android:layout_alignLeft="@id/phoneLayout"
        android:layout_alignRight="@id/phoneLayout"
        android:background="@drawable/button_shape"
        android:text="下一步"
        android:textSize="20sp"
        android:textColor="#FFFFFF"/>

</RelativeLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
效果图:

在这里插入图片描述

ForgetActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class ForgetActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget);

        //下一步按钮
        findViewById(R.id.nextButton).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ForgetActivity.this, ComfirmActivity.class);
                startActivity(intent);
            }

        });
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

activity_comfirm.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/codeLayout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/input_shape">

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:inputType="number"
            android:hint="请输入验证码"
            android:paddingLeft="10dp"
            android:background="@null"/>

        <View
            android:layout_width="1dp"
            android:layout_height="25dp"
            android:background="@color/inputColor"
            android:layout_gravity="center_vertical"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="获取验证码"
            android:background="@null"
            android:textColor="@color/inputColor"
            android:textSize="16sp"/>

    </LinearLayout>

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/codeLayout"
        android:layout_marginTop="20dp"
        android:layout_alignLeft="@+id/codeLayout"
        android:layout_alignRight="@+id/codeLayout"
        android:background="@drawable/input_shape"
        android:hint="请输入新密码(6~20位英文或数字)"
        android:paddingLeft="10dp"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/password"
        android:layout_marginTop="40dp"
        android:layout_alignLeft="@id/password"
        android:layout_alignRight="@id/password"
        android:background="@drawable/button_shape"
        android:text="确认"
        android:textSize="20sp"
        android:textColor="#FFFFFF"/>


</RelativeLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
效果图:

在这里插入图片描述

ComfirmActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class ComfirmActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comfirm);
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

part3:

activity_register.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/phoneLayout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="40dp"
        android:background="@drawable/input_shape"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="+86"
            android:textSize="16sp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"/>

        <View
            android:layout_width="1dp"
            android:layout_height="25dp"
            android:background="@color/inputColor"
            android:layout_gravity="center_vertical"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:inputType="phone"
            android:hint="请输入手机号"
            android:textColor="@color/inputColor"
            android:paddingLeft="10dp"
            android:background="@null"/>

    </LinearLayout>

    <Button
        android:id="@+id/registerButton"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@id/phoneLayout"
        android:layout_marginTop="40dp"
        android:layout_alignLeft="@id/phoneLayout"
        android:layout_alignRight="@id/phoneLayout"
        android:text="注册"
        android:textSize="20sp"
        android:textColor="#FFFFFF"
        android:background="@drawable/button_shape"/>

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/registerButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="同意《使用协议》"
        android:textSize="16sp"
        android:textColor="@color/inputColor"
        android:checked="true"></CheckBox>

</RelativeLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
效果图:

在这里插入图片描述

RegisterActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class RegisterActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

part4:

MainActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //忘记密码
        findViewById(R.id.forgetButton).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ForgetActivity.class);
                startActivity(intent);
            }

        });

        //跳转注册界面
        findViewById(R.id.registerButton).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
                startActivity(intent);
            }

        });

        //跳转用户中心界面
        findViewById(R.id.loginButton).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, UserInfoActivity.class);
                startActivity(intent);
            }

        });
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

activity_user_info.xml

<?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="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:paddingLeft="15dp"
            android:text="个人主页面背景"
            android:textColor="#000000"
            android:textSize="18sp"/>

        <ImageView
            android:layout_width="20dp"
            android:layout_height="match_parent"
            android:src="@drawable/point"
            android:layout_marginRight="15dp"/>

    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/inputColor"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="昵称"
            android:textSize="18sp"
            android:textColor="#000000"
            android:gravity="center_vertical"
            android:paddingLeft="15dp"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="今晚打老虎"
            android:textSize="18sp"
            android:gravity="center_vertical|right"/>

        <ImageView
            android:layout_width="20dp"
            android:layout_height="match_parent"
            android:src="@drawable/point"
            android:layout_marginRight="15dp"/>

    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/inputColor"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"/>

    <!--
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="头像"
            android:textSize="20sp"
            android:textColor="#000000"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/panda"/>

        <ImageView
            android:layout_width="30dp"
            android:layout_height="match_parent"
            android:src="@drawable/point"/>

    </LinearLayout>
    -->

</LinearLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
效果图:

在这里插入图片描述

UserInfoActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class UserInfoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_info);
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

point.png

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/854587?site
推荐阅读
相关标签