在android表布局中右对齐列 [英] Right align column in android table layout

查看:84
本文介绍了在android表布局中右对齐列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个表格,其中最后一列应位于表格的最右侧.

I want to draw a table in which last column should be at the right most side of the table.

这是表格行的样子:

Admin (2)New
Network (2)New

这应该是这样的:

Admin (2)         New
Network (2)       New

XML:

<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="45dp"
    android:gravity="center" android:background="@color/list_bg">

    <TableLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TableRow>



            <ImageView android:id="@+id/t1" android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView android:id="@+id/t2" android:typeface="normal"
                android:singleLine="true" android:textSize="14sp" android:textStyle="normal"
                android:layout_width="wrap_content" android:textColor="#000000"
                android:layout_height="wrap_content" />
            <TextView android:id="@+id/t10" android:typeface="normal"
                android:singleLine="true" android:text=" " android:textSize="14sp"
                android:textStyle="normal" android:layout_width="wrap_content"
                android:textColor="#000000" android:layout_height="wrap_content" />
            <TextView android:id="@+id/t4" android:typeface="normal"
                android:visibility="gone" android:singleLine="true" android:text="("
                android:textSize="14sp" android:textStyle="normal"
                android:layout_width="wrap_content" android:textColor="#000000"
                android:layout_height="wrap_content" />
            <TextView android:id="@+id/t5" android:typeface="normal"
                android:visibility="gone" android:singleLine="true"
                android:textSize="14sp" android:textStyle="normal"
                android:layout_width="wrap_content" android:textColor="#000000"
                android:layout_height="wrap_content" />
            <TextView android:id="@+id/t6" android:typeface="normal"
                android:visibility="gone" android:singleLine="true" android:text=")"
                android:textSize="14sp" android:textStyle="normal"
                android:layout_width="wrap_content" android:textColor="#000000"
                android:layout_height="wrap_content" />
            <ImageView android:id="@+id/t3" android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <TextView android:id="@+id/t7" android:typeface="normal"
                android:visibility="visible" android:singleLine="true" android:text="New"
                android:textSize="14sp"
                android:textStyle="normal" android:layout_width="wrap_content"
                android:textColor="#000000" android:layout_height="wrap_content" />

        </TableRow>

    </TableLayout>

</RelativeLayout>

在此xml中,t7应该位于表格的最右侧,该如何执行??

In this xml t7 should be right at right most side of the table, how to do this???

推荐答案

在这里您必须要做的

  1. 将表格行宽设置为fill_parent

,然后将android:layout_gravity="right"设置为要与表格行右对齐的textview

and set the android:layout_gravity="right" to the textview which you want to align right it to the table row

----或----

---- or ----

  1. 将权重添加到表格行内的textview中,以便它们可以对齐您想要的方式.

这篇关于在android表布局中右对齐列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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