0

我有一个 Textview,我需要在其中以正确的格式显示大量信息。我怎样才能实现它?

我想这样显示:

Title  :       Some Title.
Date   :       Date

More Info about the title.
......
......

Contact :      Contact Details.
4

4 回答 4

1

那么你必须通过计算选项之间的空间来做到这一点。

更好的方法

使用Webview使用 html 格式正确对齐内容的 html 字符串并加载 webview 并显示它。

于 2013-02-26T13:00:32.070 回答
0

如果使用 TextView 不是必需的,您可以使用 TableLayout:

<TableLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TableRow>
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="Title"
            android:layout_weight="1"/>

        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="Some Title"
            android:layout_weight="2"/>
    </TableRow>

    <TableRow>
        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="Date"
            android:layout_weight="1"/>

        <TextView 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="Some Date"
            android:layout_weight="2"/>
    </TableRow>

</TableLayout>
于 2013-02-26T13:12:23.810 回答
0

我认为有三种选择。

  1. 如果字体无关紧要,请在您的文本视图中使用 android:typeface="monospace" 并通过空格对齐
  2. 如果字体确实很重要,请在 html 中设计并使用 WebView
  3. 如果您不想使用 html,则需要通过不同的 TextView 进行布局,这总是更好。
于 2013-02-26T13:13:13.213 回答
0

正如其他人所建议的那样,WebView 是您的选择。请参阅 如何以编程方式设置/编辑 webview 的内容

但是,如果文本不需要特殊格式(例如不同的颜色、字体大小)并且唯一需要的格式是缩进,则可以在 TextView 中执行此操作。

在布局中:

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="false" />

在活动中:

    TextView tv = (TextView) findViewById(R.id.text);
    tv.setText("Title  :       Some Title.\nDate  :       Date\n\nMore Info about the title.\n......\n......\n\nContact :      Contact Details.");
于 2013-02-26T13:37:47.133 回答