在LinearLayout中,如果将其定位方向设为横向排列:android:orientation="horizontal",那么这个布局中的控件将自左向右排列。

但有时会有这样的情况:行的左边有两个控制的同时,行的右边也有一个控制。

这怎么处理呢?

我们可以将右边的控件放在另一个LinearLayout中,同时将其对齐方式设为右对齐:android:gravity="right",还有一点,这个LinearLayout的宽度设为充满父控件: android:layout_width="fill_parent"。这样就行了。

完整的XML代码如下:

Xml代码
  1. <? xml version = "1.0" encoding = "utf-8" ?>
  2. < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
  3. android:layout_width = "fill_parent"
  4. android:layout_height = "fill_parent"
  5. android:background = "@drawable/bg"
  6. android:orientation = "horizontal" >
  7. < TextView
  8. android:layout_width = "wrap_content"
  9. android:layout_height = "wrap_content"
  10. android:text = "左边1" />
  11. < TextView
  12. android:layout_width = "wrap_content"
  13. android:layout_height = "wrap_content"
  14. android:text = "左边2" />
  15. <!-- 将TextView包在另一个LinearLayout中
  16. 注意android:layout_width和android:gravity这两个属性
  17. -- >
  18. < LinearLayout
  19. android:layout_width = "fill_parent"
  20. android:layout_height = "wrap_content"
  21. android:gravity = "right" >
  22. < TextView
  23. android:layout_width = "wrap_content"
  24. android:layout_height = "wrap_content"
  25. android:layout_marginRight = "10dp"
  26. android:text = "右边" />
  27. </ LinearLayout >
  28. </ LinearLayout >
在LinearLayout中,如果将其定位方向设为横向排列:android:orientation="horizontal",那么这个布局中的控件将自左向右排列。但有时会有这样的情况:行的左边有两个控制的同时,行的右边也有一个控制。如图:这怎么处理呢?我们可以将右边的控件放在另一个LinearLayout中,同时将其对齐方式设为右对齐:android:gravity gravity:控制 组件 所包含的子元素的对齐方式,可多个组合。如(left | button) layout_gravity:控制该 组件 在父元素里的对齐方式。 开始使用studio实验吧: 1.给布局使用gravity属性:
flex布局 的一个子元素单独右侧对齐 我们可能会在 `Flexbox`容器 使用 `justify-self` 属性来实现子元素的水平对齐。但是,需要注意的是,`justify-self` 在 `Flex`布局 是无效的。 那么常见的做法是将子元素的 `margin-left` 设置为 `auto`。
LinearLayout ,如果将其定位方向设为横向排列:android:orientation="horizontal",那么这个布局 的控件将自左向右排列。 但有时会有这样的情况:行的左边有两个控制的同时,行的右边也有一个控制。 这怎么处理呢? 我们可以将右边的控件放在另一个 LinearLayout ,同时将其对齐方式设为 右对齐 :android:gravity
<?xml version="1.0" encoding="utf-8"?> < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/activity_main" android:layout_width="match_parent"
转自:http://www.cnblogs.com/xiaoran1129/archive/2013/03/26/2982954.html linearlayout 水平靠右显示方法 在安卓 ,只有垂直的 linearlayout 属性里面的内部 组件 靠左靠右才有效,同理,水平的 linearlayout 属性里面的内部 组件 靠上靠下才有效,否则无效由此考虑如何让水平 linearlayout 同一行内组
我根布局用的 LinearLayout ; 然后嵌套了一个一定高度的 LinearLayout ;为上图顶部宽度撑满父元素的矩形框;称之为“线布2”; 线布2 里又水平布局了两个线性布局; 左边的线性布局不管; 右边的线性布局里嵌套了4个button按钮; 现在的问题是: 超出 线布2 的3个button按钮无法显示; 超出 线布2 的3个button按钮无法响应点击事件