0

I have a Textview in which i need to show large information in proper format.How can i achieve it?

I want to display like this:

Title  :       Some Title.
Date   :       Date

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

Contact :      Contact Details.
Satheesh Kumar
  • 716
  • 5
  • 13

4 Answers4

1

Well you have to do it by calculating the space between the options.

The better way

Use a Webview make an html string with contents aligned properly using html formattings and load webview and display it.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
0

If using a TextView is not essential you can use 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>
vokilam
  • 10,153
  • 3
  • 45
  • 56
0

I think there are three options.

  1. If font doesn't matter use android:typeface="monospace" in your textview and align through spaces
  2. If font does matter design it in html and use a WebView
  3. If you don't want to work with html, you need to make the layout through different TextView's which is imo always better.
zubke
  • 33
  • 1
  • 6
0

As suggested by others, WebView is the option for you. See How to programmatically set / edit content of webview

However, it is possible to do it in a TextView if the text doesn't need special formatting (ex. different color, font sizes) and the only formatting required is indentation.

In layout:

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

In Activity:

    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.");
Community
  • 1
  • 1
appsroxcom
  • 2,821
  • 13
  • 17