Android实战演练【入门】

题目:购买宝宝装备——Activity知识

本文包括Activity入门、Activity生命周期、Activity启动模式、Intent的使用以及Activity的数据传递。

1,运行结果

1、运行进入界面,输入用户名和密码,点击注册,进入下个界面:
在这里插入图片描述
如下图,宝宝的右方会显示刚刚你注册的用户名和密码。(数据传递)
2、再点击立即购买GO!,进入下个界面:
在这里插入图片描述
3、宝宝的属性会增加数值。(这里我固定了数值,你也可以进行修改)
在这里插入图片描述
4、再次点击页面就返回宝宝购买属性的界面:
在这里插入图片描述
并且界面上的数值也增加了,再次点击购买也会叠加。

二,布局文件和class类文件

在这里插入图片描述

三,源代码如下

1、注册界面布局文件(activity_main.xml)代码如下:

<?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:layout_height="match_parent"
    android:background="@drawable/loading"
    tools:context=".MainActivity">
    <ImageView
        android:id="@+id/iv_head"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:src="@drawable/head"/>
    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/iv_head"
        android:layout_margin="10dp"
        android:orientation="vertical">
        <RelativeLayout
            android:id="@+id/regist_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp">
            <TextView
                android:id="@+id/tv_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:text="用户名:"
                android:textSize="20sp"/>
            <EditText
                android:id="@+id/et_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_toRightOf="@id/tv_name"
                android:hint="请输入用户名"
                android:textSize="16sp"/>
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/regist_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp">
            <TextView
                android:id="@+id/tv_psw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:text="密    码:"
                android:textSize="20sp"/>
            <EditText
                android:id="@+id/et_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_toRightOf="@id/tv_psw"
                android:hint="请输入密码"
                android:inputType="textPassword"
                android:textSize="16sp"/>
        </RelativeLayout>
    </LinearLayout>
    <Button
  • 0
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值