【Android UI】使用RelativeLayout与TableLayout实现登录界面

简介: 【Android UI】使用RelativeLayout与TableLayout实现登录界面

使用RelativeLayout与TableLayout分别实现两种登录界面,学习RelativeLayout布局


中如何对齐与调整组件相对位置,使用TableLayout实现登录界面,学习如何设置列


的长度,与对齐方式等。


RelativeLayout中使用如下属性调整组件相对位置


layout_alignParentLeft :表示组件左对齐布局


layout_alignParentRight:表示组件有对齐布局


layout_below="@+id/edit1":表示组件在edit1组件下面


layout_toRightOf="@+id/edit1":表示组件放在edit1的右边

效果图:

TableLayout实现效果:

RelatvieLayout实现登录的XML文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/RelativeLayout01"
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent">
  <TextView android:layout_height="wrap_content" 
    android:id="@+id/textView1"
    android:layout_width="wrap_content" 
    android:text="用户名:"
    android:layout_marginLeft="5dp"
    android:textColor="@color/green"
    android:layout_marginRight="5dp"
    android:layout_alignParentLeft="true">
  </TextView>
  <EditText android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_toRightOf="@+id/textView1" 
    android:id="@+id/editText1">
  </EditText>
  <TextView android:layout_height="wrap_content" 
    android:id="@+id/textView2"
    android:layout_width="wrap_content" 
    android:text="密码:"
    android:layout_marginLeft="5dp"
    android:textColor="@color/green"
    android:layout_marginRight="5dp"
    android:layout_below="@+id/editText1"
    android:layout_alignParentLeft="true">
  </TextView>
  <EditText android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_toRightOf="@+id/textView2" 
    android:id="@+id/editText2"
    android:layout_below="@+id/editText1">
  </EditText>
  <Button android:layout_height="wrap_content" 
    android:text="登录" 
    android:layout_width="wrap_content" 
    android:layout_below="@+id/editText2"
    android:layout_alignParentLeft="true" 
    android:id="@+id/button1">
  </Button>
  <Button android:layout_height="wrap_content" 
    android:text="注册" 
    android:layout_width="wrap_content" 
    android:layout_below="@+id/editText2"
    android:layout_toRightOf="@+id/button1" 
    android:id="@+id/button2">
  </Button>
</RelativeLayout>

TableLayout实现登录的XML文件

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/tableLayout1"
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent">
    <TableRow android:id="@+id/TableRow01">
      <TextView android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:text="帐号"
          android:textColor="@color/green"
          android:layout_marginLeft="5dp"
          android:layout_marginRight="5dp">
      </TextView>
      <EditText android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"/>
    </TableRow>
    <TableRow android:id="@+id/TableRow02">
      <TextView android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:text="密码"
          android:textColor="@color/green"
          android:layout_marginLeft="5dp"
          android:layout_marginRight="5dp">
      </TextView>
      <EditText android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"/>
    </TableRow>
    <TableRow android:id="@+id/TableRow03"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:gravity="right">
      <Button android:id="@+id/login_btn"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="登录"
          android:textColor="@color/green"
          />
      <Button android:id="@+id/register_btn"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="注册"
          android:textColor="@color/green"
          />
    </TableRow>
</TableLayout>
相关文章
|
2月前
|
Android开发 数据安全/隐私保护 开发者
Android自定义view之模仿登录界面文本输入框(华为云APP)
本文介绍了一款自定义输入框的实现,包含静态效果、hint值浮动动画及功能扩展。通过组合多个控件完成界面布局,使用TranslateAnimation与AlphaAnimation实现hint文字上下浮动效果,支持密码加密解密显示、去除键盘回车空格输入、光标定位等功能。代码基于Android平台,提供完整源码与attrs配置,方便复用与定制。希望对开发者有所帮助。
|
2月前
|
XML Java Android开发
Android自定义view之网易云推荐歌单界面
本文详细介绍了如何通过自定义View实现网易云音乐推荐歌单界面的效果。首先,作者自定义了一个圆角图片控件`MellowImageView`,用于绘制圆角矩形图片。接着,通过将布局放入`HorizontalScrollView`中,实现了左右滑动功能,并使用`ViewFlipper`添加图片切换动画效果。文章提供了完整的代码示例,包括XML布局、动画文件和Java代码,最终展示了实现效果。此教程适合想了解自定义View和动画效果的开发者。
150 65
Android自定义view之网易云推荐歌单界面
|
2月前
|
Android开发 开发者
Android企业级实战-界面篇-3
本文是《Android企业级实战-界面篇》系列的第三篇,主要介绍分割线和条形跳转框的实现方法,二者常用于设置和个人中心界面。文章通过具体代码示例展示了如何实现这两种UI组件,并提供了效果图。实现前需准备`dimens.xml`、`ids.xml`、`colors.xml`等文件,部分资源可参考系列第一、二篇文章。代码中详细说明了布局文件的配置,如分割线的样式定义和条形跳转框的组件组合,帮助开发者快速上手并应用于实际项目中。
|
2月前
|
XML Android开发 数据格式
Android企业级实战-界面篇-2
本文为《Android企业级实战-界面篇》系列第二篇,主要介绍三个UI模块的实现:用户资料模块、关注与粉丝统计模块以及喜欢和收藏功能模块。通过详细的XML代码展示布局设计,包括dimens、ids、colors配置文件的使用,帮助开发者快速构建美观且功能齐全的界面。文章结合实际效果图,便于理解和应用。建议配合第一篇文章内容学习,以获取完整工具类支持。
|
2月前
|
算法 Java Android开发
Android企业级实战-界面篇-1
本文详细介绍了Android企业级开发中界面实现的过程,涵盖效果展示、实现前准备及代码实现。作者通过自身经历分享了Android开发经验,并提供了`dimens.xml`、`ids.xml`、`colors.xml`和`strings.xml`等配置文件内容,帮助开发者快速构建规范化的UI布局。文章以一个具体的用户消息界面为例,展示了如何使用线性布局(LinearLayout)和相对布局(RelativeLayout)实现功能模块排列,并附带注意事项及使用方法,适合初学者和进阶开发者参考学习。
|
9月前
|
XML Java 数据库
安卓项目:app注册/登录界面设计
本文介绍了如何设计一个Android应用的注册/登录界面,包括布局文件的创建、登录和注册逻辑的实现,以及运行效果的展示。
596 1
安卓项目:app注册/登录界面设计
|
8月前
|
Android开发 数据安全/隐私保护 虚拟化
安卓手机远程连接登录Windows服务器教程
安卓手机远程连接登录Windows服务器教程
1438 4
|
9月前
|
安全 Java 网络安全
Android远程连接和登录FTPS服务代码(commons.net库)
Android远程连接和登录FTPS服务代码(commons.net库)
135 1
|
9月前
|
XML 数据可视化 Android开发
Android应用界面
Android应用界面中的布局和控件使用,包括相对布局、线性布局、表格布局、帧布局、扁平化布局等,以及AdapterView及其子类如ListView的使用方法和Adapter接口的应用。
145 0
Android应用界面
|
10月前
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
随着移动应用市场的蓬勃发展,用户对界面设计的要求日益提高。为此,掌握由Google推出的Material Design设计语言成为提升应用颜值和用户体验的关键。本文将带你深入了解Material Design的核心原则,如真实感、统一性和创新性,并通过丰富的组件库及示例代码,助你轻松打造美观且一致的应用界面。无论是色彩搭配还是动画效果,Material Design都能为你的Android应用增添无限魅力。
214 1