`
java-mans
  • 浏览: 11453963 次
文章分类
社区版块
存档分类
最新评论

Android开发--身高体重指数(BIM)计算--设计用户界面--视图(View)设计

 
阅读更多
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:设计用户界面--视图(View)设计

* 作 者: 雷恒鑫
* 完成日期: 2012 年 08 月 5 日
* 版 本 号: V1.0
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:

* 程序头部的注释结束

*/

视图界面描述:

为了输入“BMI应用程序”所需的身高体重值,大致上我们需要两个“TextView”组件用来显示填入身高 体重数字,另外也需要两个文字输入文本框用来填入身高 体重数字。我们还需要一个按钮来开始计算,而计算完也需要一个“TextView”组件来显示计算 结果,另一个“TextView”组件来显示建议。于是出版的“BMI应用程序”的视图界面图形就浮现出来了。

下面我们开始写代码,进行设计用户界面。

以下代码是把我们需要的“TextView”(文本视图) “EditText”(编辑文本) "Button"(按钮)3种界面组件添加到“LinearLayout”(线性页面布局)组件中。

以下是完整的“main。xml”界面说明代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"   
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="身高(cm)"
    />
<EditText android:id="@+id/height"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:numeric="integer"
    android:text=""
    />
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="体重(kg)"
    />
<EditText android:id="@+id/weight"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:numeric="integer"
    android:text=""
    />
<Button android:id="@+id/submit"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="计算BMI的值"
    />
<TextView  android:id="@+id/result"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text=""
    />
<TextView  android:id="@+id/suggest"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text=""
    />
</LinearLayout>

运行结果:

经验积累:

1. 因为将android:numeric指定为"integer",所以“EditText”文本框中只能输入数字。

2. android:text="" 指定 “EditText” 界面组件默认显示的文字(数字)。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics