LinearLayout中组件右对齐
在LinearLayout中,如果将其定位方向设为横向排列:android:orientation="horizontal",那么这个布局中的控件将自左向右排列。
但有时会有这样的情况:行的左边有两个控制的同时,行的右边也有一个控制。
如图:
这怎么处理呢?
我们可以将右边的控件放在另一个LinearLayout中,同时将其对齐方式设为右对齐:android:gravity="right",还有一点,这个LinearLayout的宽度设为充满父控件: android:layout_width="fill_parent"。这样就行了。
完整的XML代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左边1" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左边2" />
<!-- 将TextView包在另一个LinearLayout中
注意android:layout_width和android:gravity这两个属性
-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="右边" />
</LinearLayout> </LinearLayout>
LinearLayout中组件右对齐的更多相关文章
- LI 标签中让文章标题左对齐,日期右对齐的方法
希望实现标题在左对齐,日期在右对齐,当直接给日期的span加上float:right时,IE8和FF都OK,但IE6/7则会换行,下面给出一个简单有效的解决办法. <!DOCTYPE html ...
- JAVA 图形开发中组件对齐方法及界面开发
/*文章中用到的代码只是一部分,需要源码的可通过邮箱联系我 1978702969@qq.com*/ 在上篇博客中提到了JAVA图形界面开发时的两种布局,流式布局和边框布局. 在实际使用中可能会发现,往 ...
- Andriod中textview垂直水平居中及LinearLayout内组件的垂直布局
1.textview 垂直水平居中的设置 Android:gravity="center_vertical|center" 2.LinearLayout中设置控件垂直布局,默认的是 ...
- 解决LinearLayout中控件不能居右对齐
转载自:http://lgb168.blog.163.com/blog/static/49674438201172492935235/ 2011-08-24 21:35:25| 分类: Androi ...
- [转]解决LinearLayout中控件不能居右对齐
在LinearLayout布局时使用右对齐(android:layout_gravity="right")控件对齐方式不生效,需要设置 android:layout_weight= ...
- 音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系
音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系 原创 2014年02月11日 13:56:51 4951 0 0 刚刚过完春节,受假期综合症影响脑袋有点发 ...
- Word 中实现公式居中编号右对齐 -- 含视频教程(9)
1. 两种方法 不管你用「Word 自带公式」还是「Mathtype」,一般来说,Word 中实现公式居中编号右对齐的方法有两种.(1):表格法:(2):制表位. 2. 方法1:表格法 >> ...
- Word中如何公式居中标号右对齐
1.鼠标居中 2.插入一行三列表格 3.选中第一个表格,右键-表格属性-单元格-选项:然后回到单元格设置垂直居中,宽度为15%,同理第三个单元格,不过中间单元格也要设置,宽度为70%,这个word没有 ...
- C/C++中的内存对齐问题和pragma pack命令详解
这个内存对齐问题,居然影响到了sizeof(struct)的结果值.突然想到了之前写的一个API库里,有个API是向后台服务程序发送socket请求.其中的socket数据包是一个结构体.在发送soc ...
随机推荐
- linux installer os的驱动更新
installer os的驱动更新 linux系统可以简单的分为installer OS与运行时的OS,安装阶段识别不到硬件设备大概率因为installers OS版本较低,没有驱动来识别新的硬件,可 ...
- Python基础(一):初识基本数据类型
这个系列主要是对以往学过的Python3基础的总结和回顾. Python的基本数据类型包含数字.字符串.列表.元组.字典.集合几大类. 在介绍基本数据类型之前,先说明三个Python内建方法,有助于认 ...
- 推荐中的多任务学习-YouTube视频推荐
本文将介绍Google发表在RecSys'19 的论文<Recommending What Video to Watch Next: A Multitask Ranking System> ...
- GXOI&GZOI
T1 与或和 2s&&512MB 简明题意:求一个矩阵的所有子序列的 \(and\)和 和\(or\)和: 子矩阵的\(and\)和就是所有值\(and\)起来:\(or\)类 ...
- OpenLayers 笔记
1.加载ArcGIS MapServer var pipeLayer=new ol.layer.Tile({ extent: [11827395.404512288,3049293.321033439 ...
- redis最新版本安装及开机自启
的系统是ubuntu,安装方式有多种,一种是通过apt仓库,一种是下载源码,编译安装 1.通过apt仓库 具体命令: sudo apt-get update sudo apt-get install ...
- Java HashSet集合的子类LinkedHashSet集合
说明 HashSet保证元素的唯一性,可是元素存放进去是没有顺序的. 在HashSet下面有一个子类java.util.LinkedHashSet,它是 链表 + 哈希表(数组+链表 或者 数组+红黑 ...
- 【开源】后台权限管理系统升级到aspnetcore3.1
*:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...
- Mysql连接出现时区问题
错误提示: The server time zone value '¥x¥_¼Ð·Ç®É¶¡' is unrecognized or represents more than one time zon ...
- Kubernetes concepts 系列
kubernetes concepts overview Pod overview Replication Controller Pod Liftcycle Termination Of Pod Re ...