【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>

目录
相关文章
|
1月前
|
消息中间件 安全 数据处理
Android为什么不能在子线程更新UI
Android为什么不能在子线程更新UI
29 0
|
6天前
|
前端开发 Java Android开发
Android UI底层绘制原理
Android UI底层绘制原理
11 0
|
21天前
|
Java Android开发
Android Mediatek 禁用拨号应用的部分UI显示
Android Mediatek 禁用拨号应用的部分UI显示
12 0
|
1月前
|
编解码 Android开发 UED
安卓UI/UX设计原则:打造引人入胜的用户体验
【4月更文挑战第13天】本文探讨了安卓UI/UX设计的关键原则,包括一致性、简洁性、反馈、清晰性、效率和适应性。一致性要求视觉和行为保持一致,利用系统UI;简洁性减少用户行动,简化导航;反馈需即时且明确;清晰性强调表达清晰,布局有序;效率关注性能优化和任务简化;适应性涉及多设备适配和用户多样性。遵循这些原则,可创建出色应用,提供无缝用户体验。设计应持续迭代,适应技术发展和用户需求。
|
1月前
|
XML 移动开发 Android开发
构建高效安卓应用:采用Jetpack Compose实现动态UI
【4月更文挑战第10天】 在现代移动开发中,用户界面的流畅性和响应性对于应用的成功至关重要。随着技术的不断进步,安卓开发者寻求更加高效和简洁的方式来构建动态且吸引人的UI。本文将深入探讨Jetpack Compose这一革新性技术,它通过声明式编程模型简化了UI构建过程,并提升了性能与跨平台开发的可行性。我们将从基本概念出发,逐步解析如何利用Jetpack Compose来创建具有数据动态绑定能力的安卓应用,同时确保应用的高性能和良好用户体验。
19 0
|
1月前
|
XML Java Android开发
Android之UI基础控件
Android之UI基础控件
|
1月前
|
XML 开发工具 Android开发
构建高效的安卓应用:使用Jetpack Compose优化UI开发
【4月更文挑战第7天】 随着Android开发不断进化,开发者面临着提高应用性能与简化UI构建流程的双重挑战。本文将探讨如何使用Jetpack Compose这一现代UI工具包来优化安卓应用的开发流程,并提升用户界面的流畅性与一致性。通过介绍Jetpack Compose的核心概念、与传统方法的区别以及实际集成步骤,我们旨在提供一种高效且可靠的解决方案,以帮助开发者构建响应迅速且用户体验优良的安卓应用。
|
2月前
|
XML API Android开发
【Android 从入门到出门】第三章:使用Hilt处理Jetpack Compose UI状态
【Android 从入门到出门】第三章:使用Hilt处理Jetpack Compose UI状态
34 4
|
Android开发
《Android UI基础教程》——导读
本节书摘来自异步社区《Android UI基础教程》一书中的目录,作者 【美】Jason Ostrander,更多章节内容可以访问云栖社区“异步社区”公众号查看
772 0