(转)DroidDraw 教程二: Table Layout

来源:互联网 发布:淘宝网购物如何支付 编辑:程序博客网 时间:2024/05/22 06:59

DroidDraw 教程二: Table Layout

  • 步骤零

本教程描述如何创建一个从DroidDraw简单的输入和TableLayout布局。本教程假设你已经下载并安装了Android SDK。本教程也假设你对GUI编程概念和Java编程语言相当熟悉。

  • 步骤一

启动 DroidDraw 用户界面设计器

  • 步骤二

根布局选择为RelativeLayout布局
1.png

  • 步骤三

选择"Layouts"标签
图片12.png

  • 步骤四

把一个TableLayout对象从Layouts面板中拖放到屏幕顶的中部。
图片13.png

  • 步骤五

双击"TableLayout"来修改它的属性。把它的宽度"width"改为"fill_parent"
图片14.png

  • 步骤六

把三个TableRow对象从Layouts面板中拖放到TableLayout对象中。当你拖放TableRow对象时,你应该从弹出菜单中选择TableLayout。
图片15.png

  • 步骤七

每一个TableRow中拖放一个TextView:
图片16.png

  • 步骤八

双击每一个TextView来修改它的属性,修改显示文本如下图一样:
图片17.png

  • 步骤九

每一个TableRow中拖放一个EditText,放在存在的文本右边。
图片18.png

  • 步骤十

选中TableLayout,修改"Stretchable Column"(可扩展栏)属性值为1,这将把所有的EditText widget 扩展开来填充满该Table表格。
图片19.png

  • 步骤十一

编辑每一个EditText的属性,让Text文本属性为""
图片20.png

  • 步骤十二

把一个Button 拖放到TableLayout下面的右下角空白处。它应该在TableLayout的外面并和它右对齐。
图片21.png

  • 步骤十三

修改该按钮的属性,文本设置为"OK"
图片22.png

 

 

  • 步骤十四

点击"Generate"按钮来生成.xml文件

  • 步骤十五

在Eclipse中,创建一个新的Android工程

  • 步骤十六

用第十五步骤生成的XML来替换res/layouts/mian.xml文件内容。

  • 步骤十七

运行你的新工程,你应该在Android中看到你的GUI。它应该像这样:
图片23.png

  • 完整XML文件
  1. android:id="@+id/widget49"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. xmlns:android="http://schemas.android.com/apk/res/android">
  5.     android:id="@+id/widget54"
  6.     android:layout_height="160px"
  7.     androidrientation="vertical"
  8.     android:stretchColumns="1"
  9.     android:layout_alignParentTop="true"
  10.     android:layout_centerHorizontal="true" android:layout_width="fill_parent">
  11.    
  12.         android:id="@+id/widget55"
  13.         android:layout_width="fill_parent"
  14.         android:layout_height="wrap_content"
  15.         androidrientation="horizontal">
  16.        
  17.             android:id="@+id/widget58"
  18.             android:layout_width="wrap_content"
  19.             android:layout_height="wrap_content"
  20.             android:text="Name">
  21.       
  22.       
  23.             android:id="@+id/widget61"
  24.             android:layout_width="wrap_content"
  25.             android:layout_height="wrap_content"
  26.             android:textSize="18sp">
  27.        
  28.    
  29.    
  30.         android:id="@+id/widget56"
  31.         android:layout_width="fill_parent"
  32.         android:layout_height="wrap_content"
  33.         androidrientation="horizontal">
  34.        
  35.             android:id="@+id/widget59"
  36.             android:layout_width="wrap_content"
  37.             android:layout_height="wrap_content"
  38.             android:text="hone">
  39.        
  40.        
  41.             android:id="@+id/widget62"
  42.             android:layout_width="wrap_content"
  43.             android:layout_height="wrap_content"
  44.             android:textSize="18sp">
  45.        
  46.    
  47.    
  48.         android:id="@+id/widget57"
  49.         android:layout_width="fill_parent"
  50.         android:layout_height="wrap_content"
  51.         androidrientation="horizontal">
  52.        
  53.             android:id="@+id/widget60"
  54.             android:layout_width="wrap_content"
  55.             android:layout_height="wrap_content"
  56.             android:text="E-Mail">
  57.        
  58.        
  59.             android:id="@+id/widget63"
  60.             android:layout_width="wrap_content"
  61.             android:layout_height="wrap_content"
  62.             android:textSize="18sp">
  63.        
  64.    
  65.     android:id="@+id/widget64"
  66.     android:layout_width="wrap_content"
  67.     android:layout_height="wrap_content"
  68.     android:text="Button"
  69.     android:layout_below="@+id/widget54"
  70.     android:layout_alignRight="@+id/widget54">

  • 结果

图片24.png