第零步 本教程将向您简单介绍一下使用DroidDraw UI设计软件开发Android GUI应用程序。 本教程假设您已经下载并安装了Android的SDK。 本教程还假设你有一定的GUI编程和Java语言编程的基础。 第一步 转到 DroidDraw UI设计软件。 第二步 首先设置根布局为RelativeLayout(相对布局) 第三步 第四步 从布局面板中,将一个LinearLayout对象拖放在屏幕顶部中心位置。 第五步 选择LinearLayout对象,在属性选项卡上单击"Properties"布局属性,开始编辑的。 改变Width为“200 px”,Height为“130px” |
第六步 第七步 把两个EditText和两个TextView插入LinearLayout中,如图交替排列摆放。 第八步 接下来,把一个RadioGroup对象拖放到的LinearLayout中。 把两个RadioButton拖放到RadioGroup对象中。 第九步 把一个Button 对象拖放到根RelativeLayout 中,它在LinearLayout 对象下面。它应该和LinearLayout 的右边对齐。 第十步 编辑每个TextView 对象的属性值。上面一个的文本设置成"Dollars",并设置成"bold"字体样式。下面一个 TextView 的文本设置成"Euros",并也设置成"bold"字体样式 第十一步 编辑上的EditText如下的属性:
第十一步半 重复步骤十一,在"Euros"TextView 下面的第二个EditText 上,但是把id 设置为"@+id/euros" |
十二步 编辑第一个单选按钮,以便其内容为"Dollars to Euros",并把它id 设置成"@+id/dtoe"。 重要注意事项: 十三步 编辑按钮,内容为“Convert”和它的ID是“@+id/convert”。 十四步 按“Generate”按钮以生成布局的XML。 十五步 在Eclipse中创建一个新的Android项目。 剪切和粘贴DroidDraw的XML内容,以取代res/layout/main.xml。 十六步 最后一步是实际货币转换的代码。 没有多少吧,你可以使用代码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 } |
DroidDraw教程
最新推荐文章于 2022-05-20 22:17:28 发布