背景

有时以列表形式展示控件时,需要保持上下控件对齐.

效果图

“用户账号:”和“密码:”居左或居右对齐,同时后面的输入框也对齐.

实现方案

利用TableLayout实现,里面嵌套TableRow.

实现描述列居左对齐

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center">

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="用户账号:" />

android:id="@+id/editText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:width="100dp" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="密码:" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:width="100dp" />

实现描述列居右对齐

在TextView中增加了android:textAlignment="textEnd"属性

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center">

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="用户账号:"

android:textAlignment="textEnd" />

android:id="@+id/editText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:width="100dp" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="密码:"

android:textAlignment="textEnd" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:width="100dp" />

android layout 对齐,安卓利用TableLayout实现控件列对齐相关推荐

  1. android layout 替换,LayoutInflater 后记--替换系统控件

    之前记录了自己走通 LayoutInflater 的源码整体流程,一直想搞个好玩的东西,想起之前看到过的换肤方案,决定写个换系统控件的库. 项目地址,项目的具体使用,可以看README 首先需要确定, ...

  2. android控件的对齐方式

    android:layout_above 将该控件的底部至于给定ID的控件之上 android:layout_below 将该控件的顶部至于给定ID的控件之下 android:layout_toLef ...

  3. android控件的对齐方式(转)

    <?xml version="1.0" encoding="utf-8"?> <!-- android:layout_above 将该控件的底 ...

  4. android相对控件居中对齐,相对布局(RelativeLayout)常用属性

    RelativeLayout子控件的一些属性: //相对于同级控件对齐方式 android:layout_alignBaseline     将该控件的baseline与给定ID的baseline对齐 ...

  5. android控件的对齐方式,控件布局(顶部、底部)留着自用~~~

    <?xml version="1.0" encoding="utf-8"?> <!-- android:layout_above 将该控件的底 ...

  6. android 动态控件对齐,android控件的对齐方式

    android:layout_above 将该控件的底部至于给定ID的控件之上 android:layout_below 将该控件的顶部至于给定ID的控件之下 android:layout_toLef ...

  7. 『安卓』安卓开发基础--基本控件

    1. Textview 显示文字,相当于Panel.一般用来文本展示,继承自android.view.View,在android.widget包中. <TextView//控件id androi ...

  8. 安卓学习 之 UI控件(三)

    一.常用控件 1.TextView(文本) match_parent:控件与父类相同(基本不用fil_parent)wrap_content:刚好包裹里面内容. android:gravity调节文字 ...

  9. android 固定底部 布局_Android系统列表控件

    在android系统控件中,有多个控件可以展示列表数据. 一.ListView 该组件是android中最常用的一个UI组件,用于实现在屏幕上显示多个内容,以便于我们用手指进行滑动. ListView ...

最新文章

  1. AI战“疫“之路:​揭秘高精准无感测温系统的全栈AI 技术
  2. android Service oncreate 在UI线程 何时用service,何时用thread
  3. 规格选择_Axure教程:实现商品规格选择功能
  4. 【ARM】ARM体系结构-GPIO
  5. LeetCode 2062. 统计字符串中的元音子字符串
  6. 一个合格的CloudNative应用:程序当开源软件编写,应用配置外置
  7. Appium 解决手势密码 (java篇)
  8. Stm32:地址空间划分
  9. Extjs中引入JSP页面
  10. 值类型和引用类型 是什么 区别
  11. 新中大财务软件银色快车问题合集汇总 您遇到的问题基本都可以解决 SE
  12. Linux中vim的安装和使用
  13. 手机客户端(EZview/智U)添加设备时,为什么会提示“该设备已被其他账号添加”?
  14. 数据挖掘与分析应用2:大厂制作周报报表制作方法与标准格式,联动使用index和match配合sumif和sumifs函数
  15. 在保护继承中基类的共有成员_鸡啄米:C++编程入门系列之三十八(继承与派生:派生类对基类成员的访问控制之保护继承与私有继承)...
  16. 日记记事本java实训,黑马学习日记  GUI实现简单记事本功能
  17. ijkPlayer中的错误码
  18. 在国内外市场均遭遇挫折的OPPO和vivo该反思了
  19. RFID技术在智能超市中的应用
  20. freemarker(FTL)常见语法大全

热门文章

  1. toFixed()方法
  2. 日志服务商业化计费FAQ和账单优化
  3. 20135203齐岳 信息安全系统设计基础第十三周学习总结
  4. java使用链栈实现数制转换
  5. XML表示的数据库数据
  6. phpstrom函数注释模板_PHPstorm 函数时间注释的修改
  7. Asp.net控件之异同:HTML控件与Web服务器控件
  8. 用url传值,如何传多个值
  9. 深度解析JAVA动态代理设计模式
  10. struts2.0获取各种表单的数据