DroidDraw教程

第零步

本教程将向您简单介绍一下使用DroidDraw UI设计软件开发Android GUI应用程序。 本教程假设您已经下载并安装了Android的SDK。 本教程还假设你有一定的GUI编程和Java语言编程的基础。

第一步

转到 DroidDraw UI设计软件。

第二步

首先设置根布局为RelativeLayout(相对布局)

clip_image002

第三步

选择“Layouts”选项卡。 
clip_image004

第四步

从布局面板中,将一个LinearLayout对象拖放在屏幕顶部中心位置。 
clip_image006

第五步

选择LinearLayout对象,在属性选项卡上单击"Properties"布局属性,开始编辑的。 改变Width为“200 px”,Height为“130px”

点击“Apply”应用更改。 
clip_image008

第六步

转到“Widgets”标签。 
clip_image010

第七步

把两个EditText和两个TextView插入LinearLayout中,如图交替排列摆放。 
clip_image012

第八步

接下来,把一个RadioGroup对象拖放到的LinearLayout中。 把两个RadioButton拖放到RadioGroup对象中。 
clip_image014

第九步

把一个Button 对象拖放到根RelativeLayout 中,它在LinearLayout 对象下面。它应该和LinearLayout 的右边对齐。 
clip_image016

第十步

编辑每个TextView 对象的属性值。上面一个的文本设置成"Dollars",并设置成"bold"字体样式。下面一个

TextView 的文本设置成"Euros",并也设置成"bold"字体样式

第十一步

编辑上的EditText如下的属性:

  • 更改ID为:“@+id/dollars”
  • 更改文本内容为空
  • 改变宽度为“100px”。

第十一步半

重复步骤十一,在"Euros"TextView 下面的第二个EditText 上,但是把id 设置为"@+id/euros"

十二步

编辑第一个单选按钮,以便其内容为"Dollars to Euros",并把它id 设置成"@+id/dtoe"。 
编辑第二个单选按钮,以便其内容为"Euros to Dollars ",并把它id 设置成"@+id/etod"。

重要注意事项: 
你必须得到的ID完全正确,这是因为在源代码中你将通过ID查找相应的部件。

十三步

编辑按钮,内容为“Convert”和它的ID是“@+id/convert”。

最终的图形用户界面应该是这样的: 
clip_image018

十四步

按“Generate”按钮以生成布局的XML。

十五步

在Eclipse中创建一个新的Android项目。 剪切和粘贴DroidDraw的XML内容,以取代res/layout/main.xml。

此时运行, 它应该是这个样子: 
clip_image020

十六步

最后一步是实际货币转换的代码。 没有多少吧,你可以使用代码this.findViewById(R.id.)查找你的GUI元素,

下面是完整CurrentConverter Activity 的代码:

1   import android .app .Activity; 
2   import android .os .Bundle; 
3   import android .view .View; 
4   import android .view .View .OnClickListener; 
5   import android .widget .Button; 
6   import android .widget .RadioButton; 
7   import android .widget .TextView; 
8  
9   public class CurrencyConverter  extends Activity  implements OnClickListener { 
10     TextView dollars; 
11     TextView euros; 
12     RadioButton dtoe; 
13     RadioButton etod; 
14     Button convert; 
15     
16      /* *   Called   when   the   activity   is   first   created.   */ 
17     @Override 
18      public void onCreate(Bundle icicle) { 
19          super .onCreate(icicle); 
20         setContentView(R .layout .main); 
21          
22         dollars  = (TextView) this .findViewById(R .id .dollars); 
23         euros  = (TextView) this .findViewById(R .id .euros); 
24          
25         dtoe  = (RadioButton) this .findViewById(R .id .dtoe); 
26         dtoe .setChecked( true); 
27         etod  = (RadioButton) this .findViewById(R .id .etod); 
28          
29         convert  = (Button) this .findViewById(R .id .convert); 
30         convert .setOnClickListener( this); 
31     } 
32      
33      public void onClick(View v) { 
34          if (dtoe .isChecked()) { 
35             convertDollarsToEuros(); 
36         } 
37          if (etod .isChecked()) { 
38             convertEurosToDollars(); 
39         } 
40     } 
41     
42      protected void convertDollarsToEuros() { 
43          double val  = Double .parseDouble(dollars .getText() .toString()); 
44          //   in   a   real   app,   we'd   get   this   off   the   'net 
45         euros .setText(Double .toString(val * 0 . 67)); 
46     } 
47     
48      protected void convertEurosToDollars() { 
49          double val  = Double .parseDouble(euros .getText() .toString()); 
50          //   in   a   real   app,   we'd   get   this   off   the   'net 
51         dollars .setText(Double .toString(val / 0 . 67)); 
52     } 
53 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值