方法1:利用android:layout_weight
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hello_world" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello_world2" />
hello_world2的宽度会挤压hello_world的空间。
效果图:

方法2:设置LinearLayout属性 android:gravity="right"
注:只有在LinearLayout的layout_width="match_parent"才有效。
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="horizontal">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello_world" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello_world2" />
效果图:

方法三: 从右到左布局(RTL Layout)
从Android 4.2开始,Android SDK支持一种从右到左(RTL,Right-to-Left)UI布局的方式,尽管这种布局方式经常被使用在诸如阿拉伯语、希伯来语等环境中,中国用户很少使用。不过在某些特殊用途中还是很方便的。
所谓RTL,就是指按平常习惯在左的视图都会在右侧,在右侧的视图都会在左侧。例如,在线性布局中第1个子视图默认都是在左上角的,如果采用RTL布局,默认就在右上角了。
RTL布局默认是关闭的,如果想使用RTL布局,首先要在AndroidManifest.xml文件中将标签的android:supportsRtl属性值设为"true",然后需要将相应视图标签的android:layoutDirection属性值设为"rtl"。
注意:RTL布局常用android:layout_marginStart和android:layout_marginEnd来设置两个视图的间距。
android:layout_marginStart:如果在LTR布局模式下,该属性等同于android:layout_marginLeft。如果在RTL布局模式下,该属性等同于android:layout_marginRight。
android:layout_marginEnd:如果在LTR布局模式下,该属性等同于android:layout_marginRight。如果在RTL布局模式下,该属性等同于android:layout_marginLeft。
例如:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="horizontal" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#F00"
android:text="TextView1"
android:textSize="30sp" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:background="#F00"
android:text="TextView2"
android:textSize="30sp" />
效果如下:

Android中的LinearLayout布局
LinearLayout : 线性布局 在一般情况下,当有很多控件需要在一个界面列出来时,我们就可以使用线性布局(LinearLayout)了, 线性布局是按照垂直方向(vertical)或水平方向 ...
[Android学习笔记]LinearLayout布局,剩余空间的使用
转自:http://segmentfault.com/q/1010000000095725 如果使得一个View占用其父View的剩余空间? 答案是使用:android:layout_weight = ...
Android教程-03 常见布局的总结
常见的布局 视频建议采用超清模式观看, 欢迎点击订阅我的优酷 Android的图形用户界面是由多个View和ViewGroup构建出来的.View是通用的UI窗体小组件,比如按钮(Button)或者文 ...
android中的常用布局管理器(三)
接上篇博客 (5)TableLayout 表格布局管理器 在android中,线性布局和表格布局用的是最多的. 在很多的输出操作中,往往会使用表格的形式对显示的数据进行排版,tablelayo ...
Android学习——LinearLayout布局实现居中、左对齐、右对齐
android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一 ...
Android四种基本布局(LinearLayout \ RelativeLayout \ FrameLayout \ TableLayout)
------------------------------------------LinearLayout---------------------------------------------- ...
15.Android中LinearLayout布局一些小记录
在App中,我们经常看到布局中会有分割线,直接上代码: <?xml version="1.0" encoding="utf-8"?>
Android布局_布局概述和LinearLayout布局
一.布局概述: 布局为UI提供了一个可视化的结构,比如对于一个activity或者app widget的UI,你可以用两种方式声明布局: 在XML中声明UI元素 在运行时实例化布局元素(在java代码 ...
Android:控件布局(线性布局)LinearLayout
LinearLayout是线性布局控件:要么横向排布,要么竖向排布 决定性属性:必须有的! android:orientation:vertical (垂直方向) .horizontal(水平方向) ...
随机推荐
机器学习——Logistic回归
1.基于Logistic回归和Sigmoid函数的分类 2.基于最优化方法的最佳回归系数确定 2.1 梯度上升法 参考:机器学习--梯度下降算法 2.2 训练算法:使用梯度上升找到最佳参数 Logis ...
Android开发环境建立
一.For windows 7(注:XP会有问题) 1.JDK-Java SE download: http://www.oracle.com/technetwork/java/javase/down ...
可提高工作效率的 PL/SQL Developer 设置
1.将Window List 列表展示出来并保存当前布局 ①Tools-->Windows List (展示窗口列表) ②Window-->Save Layout (保存当前布局) 2.设 ...
OAuth 2.0 for MVC, Two Legged Implementation
OAuth 2.0 for MVC, Two Legged Implementation tdupont Fri, Mar 18 2011 9:30 AM 13 OAuth 1.0 was one ...
zlib1.2.11静态编译
1.进入官网http://zlib.net/,下载且解压zlib1211.zip: 2. 打开已解压的zlib-1.2.11目录,找到win32文件夹 3.将Makefile.msc复制到上一层,也就 ...
菜鸟之旅——.NET垃圾回收机制
.NET的垃圾回收机制是一个非常强大的功能,尽管我们很少主动使用,但它一直在默默的在后台运行,我们仍需要意识到它的存在,了解它,做出更高效的.NET应用程序:下面我分享一下我对于垃圾回收机制(GC)的 ...
Struts2与Spring整合
前言 本博文主要讲解Spring怎么与Struts2框架整合... Struts2和Spring的整合关键点: action对象交给Spring来创建 搭建环境 进入jar包 引入jar文件: 1)引 ...
20190320xlVBA_考场座位设置
花了一写时间做了一个Excel宏工作簿,可以根据考场人数.座位排列和考生名单 生成,想要的前往了解哦: https://i ...
Java序列化反序列化对象流ObjectInputStream、ObjectOutputStream
使用Person类作为Object进行示范 注意:Object要能被写入流需要实现Serializable接口 存储的文件后缀名为.ser 示范Person类 import java.io.Seria ...
zoj 3362(最大费用)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3904 思路:费用流的题,增加一个超级源点和一个超级汇点,然后就是连边 ...