如何按顺序对齐输出文本 [英] How to align the output text in order

查看:51
本文介绍了如何按顺序对齐输出文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以正确格式对齐文本的问题

I am facing a problem aligning the text in proper format

EX:说我要通过以下方式打印输出

EX: say I am to get printout in the following way

Name                     Phone No.
Adithya                  99999999999 
Ravi                     99999999999 
Teja                     99999999999
:
:

,但是由于字符串 Adithya 的长度不等于 Ravi 的长度,因此我们无法给出

but as the length of the String Adithya is not equal to length of Ravi we cannot give specific spacing such as

字符串s =名称+" +电话+"\ n";

在这里,如果我愿意,我将通过以下方式获得帮助

here if I give so I'll get in the following way

Name                Ph
Adithya              9999999
Ravi              9999999
Tej              9999999
:
:

它将以这种方式显示.我该如何解决?

it will display in this way. How can I solve this?

推荐答案

我宁愿建议您使用表布局(它将保证您的对齐),而不是使代码复杂.

I would rather suggest you to use Table Layout (it will guarantee you alignment) instead of making your code complex.

以下将是您的列表视图 ROW的布局只需切换到新布局,您的编码部分将相同

The following will be the layout for your list view ROW Your coding part will be same just switch to this new layout

   <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:stretchColumns="1">


        <TableRow
            android:id="@+id/tblRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"        
            android:padding="5dip">


      <TextView 
          android:id="@+id/tv_Name" 
          android:layout_width="0dip"
          android:layout_weight="3"   <!--it defines how much space this view should get in row-->
          android:text="Ravi"
          android:layout_height="wrap_content" 
          android:paddingLeft="20dip"
          android:textSize="14sp"
          android:textColor="@android:color/black"/>

       <TextView 
          android:id="@+id/tv_PhoneNumber" 
          android:layout_width="0dip"
          android:layout_weight="3"
          android:text="9999999999"
          android:layout_height="wrap_content" 
          android:paddingLeft="20dip"
          android:textSize="14sp"
          android:textColor="@android:color/black"/>   

      </TableRow>

    </TableLayout>

然后像使用其他布局一样将此布局绑定到适配器.

Then bind this layout to your adapter like you do with other Layouts..

这篇关于如何按顺序对齐输出文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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