【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>
相关文章
|
6天前
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
随着移动应用市场的蓬勃发展,用户对界面设计的要求日益提高。为此,掌握由Google推出的Material Design设计语言成为提升应用颜值和用户体验的关键。本文将带你深入了解Material Design的核心原则,如真实感、统一性和创新性,并通过丰富的组件库及示例代码,助你轻松打造美观且一致的应用界面。无论是色彩搭配还是动画效果,Material Design都能为你的Android应用增添无限魅力。
21 1
|
30天前
|
存储 搜索推荐 Java
探索安卓开发中的自定义视图:打造个性化UI组件Java中的异常处理:从基础到高级
【8月更文挑战第29天】在安卓应用的海洋中,一个独特的用户界面(UI)能让应用脱颖而出。自定义视图是实现这一目标的强大工具。本文将通过一个简单的自定义计数器视图示例,展示如何从零开始创建一个具有独特风格和功能的安卓UI组件,并讨论在此过程中涉及的设计原则、性能优化和兼容性问题。准备好让你的应用与众不同了吗?让我们开始吧!
|
30天前
|
编解码 Android开发
【Android Studio】使用UI工具绘制,ConstraintLayout 限制性布局,快速上手
本文介绍了Android Studio中使用ConstraintLayout布局的方法,通过创建布局文件、设置控件约束等步骤,快速上手UI设计,并提供了一个TV Launcher界面布局的绘制示例。
34 1
|
1月前
|
API Android开发
Android项目架构设计问题之选择和使用合适的UI库如何解决
Android项目架构设计问题之选择和使用合适的UI库如何解决
39 0
|
1月前
|
开发工具 Android开发
|
27天前
|
Android开发 iOS开发 C#
Xamarin.Forms:从零开始的快速入门指南——打造你的首个跨平台移动应用,轻松学会用C#和XAML构建iOS与Android通用界面的每一个步骤
【8月更文挑战第31天】Xamarin.Forms 是一个强大的框架,让开发者通过单一共享代码库构建跨平台移动应用,支持 iOS、Android 和 Windows。使用 C# 和 XAML,它简化了多平台开发流程并保持一致的用户体验。本指南通过创建一个简单的 “HelloXamarin” 应用演示了 Xamarin.Forms 的基本功能和工作原理。
39 0
|
1月前
|
前端开发 关系型数据库 MySQL
Python基于Django框架图书管理系统,Bootstrap框架UI,后台EasyUI框架UI,有登录,实现增删改查的富文本效果
本文介绍了一个使用Python Django框架开发的图书管理系统,该系统采用Bootstrap框架进行前端UI设计,EasyUI框架用于后台UI界面,集成了富文本编辑器,并实现了登录及增删改查功能。
|
1月前
|
安全 Java 网络安全
Android远程连接和登录FTPS服务代码(commons.net库)
很多文章都介绍了FTPClient如何连接ftp服务器,但却很少有人说如何连接一台开了SSL认证的ftp服务器,现在代码来了。
74 2
|
2月前
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
【7月更文挑战第28天】随着移动应用市场的发展,用户对界面设计的要求不断提高。Material Design是由Google推出的设计语言,强调真实感、统一性和创新性,通过模拟纸张和墨水的物理属性创造沉浸式体验。它注重色彩、排版、图标和布局的一致性,确保跨设备的统一视觉风格。Android Studio提供了丰富的Material Design组件库,如按钮、卡片等,易于使用且美观。
91 1
|
2月前
|
Android开发 索引
Android流布局实现筛选界面
Android流布局实现筛选界面
38 0