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>
效果图:

在这里插入图片描述

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>
效果图:

在这里插入图片描述

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>
效果图:

在这里插入图片描述

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>
效果图:

在这里插入图片描述

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);
            }

        });
    }

}

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>
效果图:

在这里插入图片描述

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);
    }

}

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>
效果图:

在这里插入图片描述

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);
    }

}

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);
            }

        });
    }

}

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>
效果图:

在这里插入图片描述

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);
    }

}

point.png

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值