DroidDraw教程[转]
转自:http://blog.csdn.net/archfree/article/details/6001871
第零步
本教程将向您简单介绍一下使用DroidDraw UI设计软件开发Android GUI应用程序。 本教程假设您已经下载并安装了Android的SDK。 本教程还假设你有一定的GUI编程和Java语言编程的基础。
第一步
转到 DroidDraw UI设计软件。
第二步
首先设置根布局为RelativeLayout(相对布局)
第三步
第四步
从布局面板中,将一个LinearLayout对象拖放在屏幕顶部中心位置。 
第五步
选择LinearLayout对象,在属性选项卡上单击"Properties"布局属性,开始编辑的。 改变Width为“200 px”,Height为“130px”,点击“Apply”应用更改。
第六步
第七步
把两个EditText和两个TextView插入LinearLayout中,如图交替排列摆放。 
第八步
接下来,把一个RadioGroup对象拖放到的LinearLayout中。 把两个RadioButton拖放到RadioGroup对象中。 
第九步
把一个Button 对象拖放到根RelativeLayout 中,它在LinearLayout 对象下面。它应该和LinearLayout 的右边对齐。 
第十步
编辑每个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”。最终的图形用户界面应该是这样的:
十四步
按“Generate”按钮以生成布局的XML。
十五步
在Eclipse中创建一个新的Android项目。 剪切和粘贴DroidDraw的XML内容,以取代res/layout/main.xml。此时运行, 它应该是这个样子:
十六步
最后一步是实际货币转换的代码。 没有多少吧,你可以使用代码this.findViewById(R.id.)查找你的GUI元素,下面是完整CurrentConverter Activity 的代码:
1 package com.example.currencyconverter; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.view.View.OnClickListener; 7 import android.widget.Button; 8 import android.widget.RadioButton; 9 import android.widget.TextView; 10 11 public class MainActivity extends Activity implements OnClickListener { 12 TextView dollars; 13 TextView euros; 14 RadioButton dtoe; 15 RadioButton etod; 16 Button convert; 17 18 /** Called when the activity is first created. */ 19 @Override 20 public void onCreate(Bundle icicle) { 21 super.onCreate(icicle); 22 setContentView(R.layout.activity_main); 23 24 dollars = (TextView)this.findViewById(R.id.dollars); 25 euros = (TextView)this.findViewById(R.id.euros); 26 27 dtoe = (RadioButton)this.findViewById(R.id.dtoe); 28 dtoe.setChecked(true); 29 30 etod = (RadioButton)this.findViewById(R.id.etod); 31 32 convert = (Button)this.findViewById(R.id.convert); 33 convert.setOnClickListener(this); 34 } 35 36 public void onClick(View v) { 37 if (dtoe.isChecked()) { 38 convertDollarsToEuros(); 39 } 40 if (etod.isChecked()) { 41 convertEurosToDollars(); 42 } 43 } 44 45 protected void convertDollarsToEuros() { 46 double val = Double.parseDouble(dollars.getText().toString()); 47 // in a real app, we'd get this off the 'net 48 euros.setText(Double.toString(val*0.67)); 49 } 50 51 protected void convertEurosToDollars() { 52 double val = Double.parseDouble(euros.getText().toString()); 53 54 // in a real app, we'd get this off the 'net 55 dollars.setText(Double.toString(val/0.67)); 56 } 57 }






浙公网安备 33010602011771号