1. 训练目标
1.掌握组件ProgressBar的使用
2.掌握startActivityForResult方法的使用
操作步骤:
1.创建程序(主界面):
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="cn.edu.bu.a13labequipment.MainActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/baby" android:layout_gravity="center_horizontal" android:layout_marginTop="45dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="主人,快给小宝宝购买装备吧!" android:gravity="center_horizontal" android:textSize="18sp" /> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="25dp"> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="生命值:" /> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleHorizontal" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3" android:layout_marginLeft="20dp" /> <TextView android:id="@+id/tv_life" android:layout_width="0dp" android:layout_height="wrap_content" android:text="80" android:layout_marginTop="5dp" android:layout_weight="1" android:layout_marginLeft="20dp" /> </TableRow> <TableRow android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:layout_
Android--Activity会传数据(装备选择)
最新推荐文章于 2021-01-25 22:52:20 发布
本文介绍了如何在Android应用中使用Activity进行数据传递,重点在于startActivityForResult方法的运用。通过创建主界面、装备选择界面,并结合ProgressBar组件展示耗时操作的进度,提升用户体验。详细步骤包括创建各种组件、自定义Info类以及实现ShoppingActivity和MainActivity的交互,最终实现了从装备选择界面返回数据到主界面的效果。
摘要由CSDN通过智能技术生成