Kutbi
Kutbi

Reputation: 1154

how do i set text alignment line by line in single textview

Thanks in advance...

i have a string array which i want to set in textview in proper alignment.. my textview is created dynamically..

my string is :

                  private String[] mDialogue = 
                  {
                            "Copa de Agua      8 Oz\n"+
            "Copa de Vino Tinto      6 Oz\n"+
            "Copa de Vino Blanco      5 Oz\n"+
            "Copa Flauta      5 Oz\n"+
            "Copa Tulipan      6 Oz\n"+
            "Copa Cocktail      5 Oz\n"+
            "Copa Sour      5 Oz\n"+
            "Copa Borgo–a      10 Oz\n"+
            "Copa Licor      2 Oz\n"+
            "Copa Sherry      3 Oz\n"+
            "Copa Balon/Cognac      9-25 Oz\n"+
            "Copa Champagne      5 Oz\n"+
            "Copa Catavinos      3 Oz\n"+
            "Vaso High Ball      8 Oz\n"+
            "Vaso On the Rocks      6 Oz\n"+
            "Vaso Collins/Tubo      10 Oz\n"+
            "Vaso Pilsen      10 Oz\n"+
            "Jarra de Cerveza      12 Oz",

            "1 Mililitro         0,001 L\n"+
            "1 Centilitro        0,01 L\n"+
            "1 Decilitro      0,1 L\n"+
            "2 Cucharadas      10 cc\n"+
            "20 Cucharadas      10 cl\n"+
            "1 Taza      236,5 cc\n"+
            "1 Taza      23,6 cl\n"+
            "1 Golpe      1 gota\n"+
            "1 Chorro      10 gotas",
                  }

i set this string statically but for different layouts it doesn`t work properly.. when i run in my emulator its look like :i added screen shot for this.. is there any html format which i set my text in proper alignment..?? or if u have any kind of solution then please help me..enter image description here

Upvotes: 1

Views: 788

Answers (3)

Nikunj Patel
Nikunj Patel

Reputation: 22066

absolute layout , that will help to set any where at x and y position

Upvotes: -1

roger l
roger l

Reputation: 638

Actually, there are better answers than two textViews next to each other, because, then how would they scroll together? What you are looking at is the perfect place to implement a list view with a custom List Adapter and custom view that is made up of a

<RelativeLayout>
   <TextView id=@+id/left alignWithParentLeft=true/>
   <TextView id=@+id/right alignWithParentRight=true/>
<RelativeLayout>

Then your custom adapter would just loop through your data and put your 'key' in @+id/left and your 'value' in @+id/right There are plenty of great tutorials on custom list adapters, and this is a great problem to learn for.

http://jnastase.alner.net/archive/2010/12/19/custom-android-listadapter.aspx or more in depth, but not necessarily better http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

Upvotes: 4

Geobits
Geobits

Reputation: 22342

Your best bet is to use a layout with two textviews on each line. As far as I know there's no good way to do what you want in a single textview.

Upvotes: 1

Related Questions