【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月前
|
存储 消息中间件 人工智能
【04】AI辅助编程完整的安卓二次商业实战-寻找修改替换新UI首页图标-菜单图标-消息列表图标-优雅草伊凡
【04】AI辅助编程完整的安卓二次商业实战-寻找修改替换新UI首页图标-菜单图标-消息列表图标-优雅草伊凡
407 4
|
10月前
|
Android开发 数据安全/隐私保护 开发者
Android自定义view之模仿登录界面文本输入框(华为云APP)
本文介绍了一款自定义输入框的实现,包含静态效果、hint值浮动动画及功能扩展。通过组合多个控件完成界面布局,使用TranslateAnimation与AlphaAnimation实现hint文字上下浮动效果,支持密码加密解密显示、去除键盘回车空格输入、光标定位等功能。代码基于Android平台,提供完整源码与attrs配置,方便复用与定制。希望对开发者有所帮助。
186 0
|
10月前
|
XML Java Android开发
Android自定义view之网易云推荐歌单界面
本文详细介绍了如何通过自定义View实现网易云音乐推荐歌单界面的效果。首先,作者自定义了一个圆角图片控件`MellowImageView`,用于绘制圆角矩形图片。接着,通过将布局放入`HorizontalScrollView`中,实现了左右滑动功能,并使用`ViewFlipper`添加图片切换动画效果。文章提供了完整的代码示例,包括XML布局、动画文件和Java代码,最终展示了实现效果。此教程适合想了解自定义View和动画效果的开发者。
431 65
Android自定义view之网易云推荐歌单界面
|
搜索推荐 Android开发 开发者
探索安卓开发中的自定义视图:打造个性化UI组件
【10月更文挑战第39天】在安卓开发的世界中,自定义视图是实现独特界面设计的关键。本文将引导你理解自定义视图的概念、创建流程,以及如何通过它们增强应用的用户体验。我们将从基础出发,逐步深入,最终让你能够自信地设计和实现专属的UI组件。
|
10月前
|
Android开发 开发者
Android企业级实战-界面篇-3
本文是《Android企业级实战-界面篇》系列的第三篇,主要介绍分割线和条形跳转框的实现方法,二者常用于设置和个人中心界面。文章通过具体代码示例展示了如何实现这两种UI组件,并提供了效果图。实现前需准备`dimens.xml`、`ids.xml`、`colors.xml`等文件,部分资源可参考系列第一、二篇文章。代码中详细说明了布局文件的配置,如分割线的样式定义和条形跳转框的组件组合,帮助开发者快速上手并应用于实际项目中。
122 1
|
10月前
|
XML Android开发 数据格式
Android企业级实战-界面篇-2
本文为《Android企业级实战-界面篇》系列第二篇,主要介绍三个UI模块的实现:用户资料模块、关注与粉丝统计模块以及喜欢和收藏功能模块。通过详细的XML代码展示布局设计,包括dimens、ids、colors配置文件的使用,帮助开发者快速构建美观且功能齐全的界面。文章结合实际效果图,便于理解和应用。建议配合第一篇文章内容学习,以获取完整工具类支持。
153 0
|
10月前
|
算法 Java Android开发
Android企业级实战-界面篇-1
本文详细介绍了Android企业级开发中界面实现的过程,涵盖效果展示、实现前准备及代码实现。作者通过自身经历分享了Android开发经验,并提供了`dimens.xml`、`ids.xml`、`colors.xml`和`strings.xml`等配置文件内容,帮助开发者快速构建规范化的UI布局。文章以一个具体的用户消息界面为例,展示了如何使用线性布局(LinearLayout)和相对布局(RelativeLayout)实现功能模块排列,并附带注意事项及使用方法,适合初学者和进阶开发者参考学习。
218 0
|
XML 搜索推荐 前端开发
安卓开发中的自定义视图:打造个性化UI组件
在安卓应用开发中,自定义视图是一种强大的工具,它允许开发者创造独一无二的用户界面元素,从而提升应用的外观和用户体验。本文将通过一个简单的自定义视图示例,引导你了解如何在安卓项目中实现自定义组件,并探讨其背后的技术原理。我们将从基础的View类讲起,逐步深入到绘图、事件处理以及性能优化等方面。无论你是初学者还是有经验的开发者,这篇文章都将为你提供有价值的见解和技巧。
|
Android开发 数据安全/隐私保护 虚拟化
安卓手机远程连接登录Windows服务器教程
安卓手机远程连接登录Windows服务器教程
3283 5
|
XML 前端开发 Android开发
Android:UI:Drawable:View/ImageView与Drawable
通过本文的介绍,我们详细探讨了Android中Drawable、View和ImageView的使用方法及其相互关系。Drawable作为图像和图形的抽象表示,提供了丰富的子类和自定义能力,使得开发者能够灵活地实现各种UI效果。View和ImageView则通过使用Drawable实现了各种图像和图形的显示需求。希望本文能为您在Android开发中使用Drawable提供有价值的参考和指导。
409 2