Android 案例—装备选择

本文档详细介绍了如何创建一个Android应用,实现装备选择功能。首先,创建名为Select Device的工程,导入必要的图片资源,并在String.xml中设置界面标题。接着,设计装备选择界面布局,包括ImageView、TextView、TableLayout、ProgressBar以及两个操作按钮,用户可以在此选择并购买装备。
摘要由CSDN通过智能技术生成

1.创建程序

建立装备选择工程,名为Select Device,包名为cn.edu.bzu .

(1)导入图片baby、ic_launcher和bg;

(2)在String.xml文件中修改界面显示名称为“装备选择”:

<string name="app_name">装备选择</string>

2.编写装备选择界面布局文件(activity_main.xml)

在线性布局下加入:

*图片控件(ImageView)用来添加界面上的图片;

*文本控件(TextView)添加文本;

*表格布局(TableLayout)其中包含三个TableRow对象用来控制行数,分别表示‘生命值’‘攻击力’‘敏捷’,其对象中包含一个文本控件(TextView),一个进度条——用于访问网络展示Loading对话框以及下载文件时显示的进度(ProgressBar);

*相对布局(RelativeLayout);

*两个按钮(Button):分别显示‘主人购买装备’,‘小宝宝购买装备’;

如下:

<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"
    android:gravity="center"
    tools:context=".MainActivity"
    android:background="@drawable/bg">
    <ImageView
        android:id="@+id/pet_imgv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="30dp"
        android:src="@drawable/baby" />
    <TextView
        android:id="@+id/pet_dialog_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="25dp"
        android:gravity="center"
        android:textSize="16dp"
        android:text="*主人,快给小宝宝购买装备吧*" />
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp">
        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <TextView
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="生命值:"
                android:textColor="@android:color/black"
                android:textSize="14sp" />
            <ProgressBar
                android:id="@+id/progressBar1"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值