4.EditText控件的应用实例:结合TableLayout

来源:互联网 发布:linux常用命令 cat 编辑:程序博客网 时间:2024/06/16 21:27

目标效果:

    为了使应用程序布局显示不杂乱,添加了一个TableLayout表格布局文件管理器,其中页面的每一行是使用TableRow 来装控件。
  其中,整个文件是采用TableLayout表格布局器布局,对于界面中要显示的每一行,采用TableRow将该行的所有控件包含起来,在这里是两个控件一组,最后的一行是两个按钮,采用嵌套的线性布局实现。
                      

布局实现:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/TableLayout1"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" >    <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical" >        <TextView            android:text="用户名"            android:textSize="20dp" />        <EditText            android:hint="请输入用户名"            android:textSize="20dp"             android:inputType="textPersonName"/>    </TableRow>            <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical" >        <TextView            android:text="密  码"            android:textSize="20dp" />        <EditText            android:hint="请输入密码"            android:textSize="20dp"            android:password="true" />        </TableRow>                <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical" >        <TextView            android:text="确认密码"            android:textSize="20dp" />        <EditText            android:hint="请输入密码"            android:textSize="20dp"             android:inputType="textPassword"/>        </TableRow>            <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical" >        <TextView            android:text="电话号码"            android:textSize="20dp" />        <EditText            android:hint="请输入电话号码"            android:textSize="20dp"            android:inputType="phone" /></TableRow>        <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical" >        <TextView            android:text="邮箱地址"            android:textSize="20dp" />        <EditText            android:hint="请输入邮箱地址"            android:textSize="20dp"            android:inputType="textEmailAddress" />        </TableRow>                <LinearLayout             android:orientation="horizontal"            android:layout_width="wrap_content"            android:layout_height="wrap_content">                        <Button                 android:text="注册"                android:textSize="20dp"                android:layout_width="wrap_content"            android:layout_height="wrap_content"/>            <Button                 android:text="重置"                android:textSize="20dp"                android:layout_width="wrap_content"            android:layout_height="wrap_content"/>        </LinearLayout></TableLayout>



原创粉丝点击