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

简介: 使用RelativeLayout与TableLayout分别实现两种登录界面,学习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>

目录
相关文章
|
5天前
|
XML Java 数据库
安卓项目:app注册/登录界面设计
本文介绍了如何设计一个Android应用的注册/登录界面,包括布局文件的创建、登录和注册逻辑的实现,以及运行效果的展示。
33 0
安卓项目:app注册/登录界面设计
|
5天前
|
XML 数据可视化 Android开发
Android应用界面
Android应用界面中的布局和控件使用,包括相对布局、线性布局、表格布局、帧布局、扁平化布局等,以及AdapterView及其子类如ListView的使用方法和Adapter接口的应用。
9 0
Android应用界面
|
25天前
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
随着移动应用市场的蓬勃发展,用户对界面设计的要求日益提高。为此,掌握由Google推出的Material Design设计语言成为提升应用颜值和用户体验的关键。本文将带你深入了解Material Design的核心原则,如真实感、统一性和创新性,并通过丰富的组件库及示例代码,助你轻松打造美观且一致的应用界面。无论是色彩搭配还是动画效果,Material Design都能为你的Android应用增添无限魅力。
43 1
|
2月前
|
编解码 前端开发 vr&ar
从零开始的PICO教程(4)--- UI界面绘制与响应事件
这篇文章是PICO开发系列教程的第四部分,主要介绍了如何在PICO 4 VR环境中创建UI界面,包括Canvas和Panel的配置、UI元素的绘制、以及Button和Slider的事件响应绑定,并通过示例展示了数字增减和滑块功能的具体实现。
从零开始的PICO教程(4)--- UI界面绘制与响应事件
|
2月前
|
存储 搜索推荐 Java
探索安卓开发中的自定义视图:打造个性化UI组件Java中的异常处理:从基础到高级
【8月更文挑战第29天】在安卓应用的海洋中,一个独特的用户界面(UI)能让应用脱颖而出。自定义视图是实现这一目标的强大工具。本文将通过一个简单的自定义计数器视图示例,展示如何从零开始创建一个具有独特风格和功能的安卓UI组件,并讨论在此过程中涉及的设计原则、性能优化和兼容性问题。准备好让你的应用与众不同了吗?让我们开始吧!
|
2月前
|
编解码 Android开发
【Android Studio】使用UI工具绘制,ConstraintLayout 限制性布局,快速上手
本文介绍了Android Studio中使用ConstraintLayout布局的方法,通过创建布局文件、设置控件约束等步骤,快速上手UI设计,并提供了一个TV Launcher界面布局的绘制示例。
41 1
|
2月前
|
API Android开发
Android项目架构设计问题之选择和使用合适的UI库如何解决
Android项目架构设计问题之选择和使用合适的UI库如何解决
41 0
|
2月前
|
开发工具 Android开发
|
2月前
|
Android开发 iOS开发 C#
Xamarin.Forms:从零开始的快速入门指南——打造你的首个跨平台移动应用,轻松学会用C#和XAML构建iOS与Android通用界面的每一个步骤
【8月更文挑战第31天】Xamarin.Forms 是一个强大的框架,让开发者通过单一共享代码库构建跨平台移动应用,支持 iOS、Android 和 Windows。使用 C# 和 XAML,它简化了多平台开发流程并保持一致的用户体验。本指南通过创建一个简单的 “HelloXamarin” 应用演示了 Xamarin.Forms 的基本功能和工作原理。
60 0
|
2月前
|
容器 iOS开发 Linux
震惊!Uno Platform 响应式 UI 构建秘籍大公开!从布局容器到自适应设计,带你轻松打造跨平台完美界面
【8月更文挑战第31天】Uno Platform 是一款强大的跨平台应用开发框架,支持 Web、桌面(Windows、macOS、Linux)及移动(iOS、Android)等平台,仅需单一代码库。本文分享了四个构建响应式用户界面的最佳实践:利用布局容器(如 Grid)适配不同屏幕尺寸;采用自适应布局调整 UI;使用媒体查询定制样式;遵循响应式设计原则确保 UI 元素自适应调整。通过这些方法,开发者可以为用户提供一致且优秀的多设备体验。
64 0