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

查看:24
本文介绍了在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" 设置为要使其与表格行对齐的文本视图

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天全站免登陆