随着一步步深入的学习,多个Activity之间需要进行数据的回传,下面根据游戏中常见的装备的购买模拟对数据的回传进行巩固。
1:首先运用运用button,textview,edittext等控件进行UI的设计,代码如下:
<?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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="cn.edu.bzu.test1.MainActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="45dp" android:src="@drawable/baby" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="主人快给小宝宝购买装备吧!" android:textSize="18sp" /> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="25dp" android:gravity="center" > <!-- 表格中第一行--> <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_marginLeft="20dp" android:layout_weight="3" /> <TextView android:id="@+id/tv_life" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginLeft="20dp" android:layout_marginTop="5dp" android:text="80" /> </TableRow> <!-- 表格中第二行--> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" > <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="攻击力:" /> <