【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>
相关文章
|
10月前
|
机器学习/深度学习 算法 定位技术
Baumer工业相机堡盟工业相机如何通过YoloV8深度学习模型实现裂缝的检测识别(C#代码UI界面版)
本项目基于YOLOv8模型与C#界面,结合Baumer工业相机,实现裂缝的高效检测识别。支持图像、视频及摄像头输入,具备高精度与实时性,适用于桥梁、路面、隧道等多种工业场景。
1184 27
|
计算机视觉 Python
基于Dlib的人脸识别客户端(UI界面)
基于Dlib的人脸识别客户端(UI界面)
610 2
|
存储 JSON JavaScript
WEB CAD插件通过上下文对象MxPluginContext修改UI界面的方法
本文介绍了如何使用MxPluginContext动态控制MxCAD项目的UI界面。通过该上下文对象,开发者可以灵活设置UI配置,如控制操作栏显隐、编辑按钮、添加侧边栏等。具体方法包括调用`getUiConfig()`获取并修改`mxUiConfig.json`中的属性,实现界面的定制化。此外,还提供了控制命令行聚焦的功能,解决输入框焦点锁定问题。详细代码示例和效果对比图展示了具体实现步骤,帮助开发者更好地适配项目需求。
|
移动开发 前端开发 Java
Java最新图形化界面开发技术——JavaFx教程(含UI控件用法介绍、属性绑定、事件监听、FXML)
JavaFX是Java的下一代图形用户界面工具包。JavaFX是一组图形和媒体API,我们可以用它们来创建和部署富客户端应用程序。 JavaFX允许开发人员快速构建丰富的跨平台应用程序,允许开发人员在单个编程接口中组合图形,动画和UI控件。本文详细介绍了JavaFx的常见用法,相信读完本教程你一定有所收获!
14601 5
Java最新图形化界面开发技术——JavaFx教程(含UI控件用法介绍、属性绑定、事件监听、FXML)
|
开发框架 JavaScript 前端开发
HarmonyOS UI开发:掌握ArkUI(包括Java UI和JS UI)进行界面开发
【10月更文挑战第22天】随着科技发展,操作系统呈现多元化趋势。华为推出的HarmonyOS以其全场景、多设备特性备受关注。本文介绍HarmonyOS的UI开发框架ArkUI,探讨Java UI和JS UI两种开发方式。Java UI适合复杂界面开发,性能较高;JS UI适合快速开发简单界面,跨平台性好。掌握ArkUI可高效打造符合用户需求的界面。
719 8
|
编解码 前端开发 vr&ar
从零开始的PICO教程(4)--- UI界面绘制与响应事件
这篇文章是PICO开发系列教程的第四部分,主要介绍了如何在PICO 4 VR环境中创建UI界面,包括Canvas和Panel的配置、UI元素的绘制、以及Button和Slider的事件响应绑定,并通过示例展示了数字增减和滑块功能的具体实现。
从零开始的PICO教程(4)--- UI界面绘制与响应事件
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
随着移动应用市场的蓬勃发展,用户对界面设计的要求日益提高。为此,掌握由Google推出的Material Design设计语言成为提升应用颜值和用户体验的关键。本文将带你深入了解Material Design的核心原则,如真实感、统一性和创新性,并通过丰富的组件库及示例代码,助你轻松打造美观且一致的应用界面。无论是色彩搭配还是动画效果,Material Design都能为你的Android应用增添无限魅力。
528 1
|
机器学习/深度学习 数据可视化 计算机视觉
基于opencv的车牌识别系统(UI界面采用tkinter设计)
基于opencv的车牌识别系统(UI界面采用tkinter设计)
412 0
|
前端开发 关系型数据库 MySQL
Python基于Django框架图书管理系统,Bootstrap框架UI,后台EasyUI框架UI,有登录,实现增删改查的富文本效果
本文介绍了一个使用Python Django框架开发的图书管理系统,该系统采用Bootstrap框架进行前端UI设计,EasyUI框架用于后台UI界面,集成了富文本编辑器,并实现了登录及增删改查功能。
663 1
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
【7月更文挑战第28天】随着移动应用市场的发展,用户对界面设计的要求不断提高。Material Design是由Google推出的设计语言,强调真实感、统一性和创新性,通过模拟纸张和墨水的物理属性创造沉浸式体验。它注重色彩、排版、图标和布局的一致性,确保跨设备的统一视觉风格。Android Studio提供了丰富的Material Design组件库,如按钮、卡片等,易于使用且美观。
743 1