左对齐文本,复选框权 [英] Align text left, checkbox right

查看:126
本文介绍了左对齐文本,复选框权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创造一个布局一个ListView,有一个复选框权和一些文字到左边。复选框应一路靠右对齐和对准的TextView所有行向左的方式,例如:

I'm trying to create a layout for a ListView, with a checkbox to the right and some text to the left. The checkbox should be aligned all the way to the right and the TextView aligned all the way to left of the row, eg:

 ------------------------
 text            checkbox
 ------------------------
 text            checkbox
 ------------------------
 text            checkbox
 ------------------------

这是我到目前为止有:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:paddingLeft="5dip"
      android:paddingRight="5dip"
      android:paddingTop="8dip"
     android:paddingBottom="8dip"
>

<TextView  
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left" 
/>

<CheckBox 
    android:id="@+id/chekcbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right" 
 /> 

 </RelativeLayout>

然而,实际上呈现为文本框覆盖的复选框,该行的左侧。

However, what actually renders is the TextBox is overlaying the checkbox, to the left of the row.

推荐答案

既然你已经在使用一个RelativeLayout的,利用它的属性:

Since you are already using a RelativeLayout, make use of it's attributes:

删除安卓重力从儿童,并与更换安卓layout_alignParentLeft =真正的的TextView的和机器人:layout_alignParentRight =真正的对CheckBox

Remove android:gravity from the children and replace them with android:layout_alignParentLeft="true" for the TextView and android:layout_alignParentRight="true" for the CheckBox.

这位置相对于家长边界的孩子。您可能还需要添加机器人:layout_centerVertical =真正的给每个孩子各列表项中居中两个垂直

That positions the children relative to the parents borders. You may also want to add android:layout_centerVertical="true" to each child to center the two vertical within each list item.

有关更多选项和属性看<一href="http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html">documentation.

这篇关于左对齐文本,复选框权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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