如何将复选框和文本对齐到屏幕右侧? [英] How can I align checkbox with text to right side of the screen?

查看:62
本文介绍了如何将复选框和文本对齐到屏幕右侧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 TableRow 中有一个复选框.我想将复选框和文本都对齐到屏幕的右侧,但是当我使用 android:gravity ="right" 时,它只会将文本对齐到屏幕的右侧,而不对齐正方形(复选框本身).看来它们是分开对齐的(屏幕左侧的复选框和右侧的文本).

I have a checkbox inside a TableRow. I would like to align both checkbox and text to the right side of the screen but when I use android:gravity="right" it only aligns the text to the right side of the screen but not the square (the checkbox itself). It seems that they are aligned separately (checkbox on the left and text on the right side of the screen).

以下是引用该复选框的xml片段:

Here is the snippet of xml that refers to the checkbox:

<TableRow android:layout_height="wrap_content"
          android:layout_width="match_parent"
          android:layout_marginBottom="10dp">

          <CheckBox
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Select"
                android:id="@+id/checkboxSelect"
                android:layout_column="0"
                android:layout_weight="1"
                android:gravity="right"/>
</TableRow>

如何将复选框及其上的文本与屏幕右侧对齐?

How can I align both the checkbox and the text on it to the right side of the screen?

提前谢谢!

推荐答案

属性 android:gravity 在视图本身上起作用,而 android:layout_gravity 是父视图的建议对齐它的孩子.

Attribute android:gravity is working on view itself, while android:layout_gravity is suggestion for parent view to align it's child.

如果您想让父级布局在左侧或右侧对齐其子级,则有两个选择:

if you want tell parent layout to align it's child at left or right you have two options:

  1. 在父对象上使用 android:gravity ,因此父对象将尝试在该重力下对齐所有子视图.
  2. 子视图上的
  3. android:layout_gravity ,只有该视图会尝试在该重力上使其自身对齐.
  1. use android:gravity on parent, and thus parent will try to align all child views at that gravity.
  2. android:layout_gravity on child view, and only this view will try to align itself in that gravity.

这篇关于如何将复选框和文本对齐到屏幕右侧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆