1

My layout is like this:

<ScrollView
        android:id="@+id/scrollView_page1"
        android:layout_width="300dp"
        android:layout_height="700dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

             <TableRow
                 android:layout_width="fill_parent"
                 android:layout_height="60dip"
                 android:gravity="right"
                  >

             <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/string1"
                android:id="@+id/textview1"/>
             <EditText
                 android:id="@+id/edittext1"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:width="200dp"
                 android:inputType="number"/>
             </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="60dip"
                android:gravity="right"

                >
              <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/string2"
                    android:id="@+id/textview2"/>

             <Spinner
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/spinner1"
                    android:width="200dp"
                    />
                .........

The distance between TableRows seems not so regular: some of them are too close and some of them are too far. I don't want to use android:paddingTop adjust them one by one.

is there any easy way to make same distance between them? Currently it looks like this:

Picture of layout as it is now with varying row heights

Neil Townsend
  • 6,024
  • 5
  • 35
  • 52
范植勝
  • 787
  • 2
  • 6
  • 14

2 Answers2

3

@giga_abhi is spot on, but I would add that in each TableRow, you also need:

android:layout_height="0dip"

and in the LinearLayout:

android:layout_height="fill_parent"

and in the ScrollView:

android:fillViewport="true"
Neil Townsend
  • 6,024
  • 5
  • 35
  • 52
  • any idea about this issue? : http://stackoverflow.com/questions/23087668/how-do-i-wrap-a-second-text-around-first-text-title-both-are-in-text-view –  Apr 15 '14 at 15:24
  • @JusticeBauer I've had a go, but it's not exactly elegant! – Neil Townsend Apr 15 '14 at 19:15
1

In the LinearLayout set:

android:weightSum="(no of tables say 3)"`

and in each TableRow add this line:

android:layout_weight="1"`

This will form TableRow with same height as your orientation is Vertical. The only part remains is adjusting height of elements inside TableRow.

Neil Townsend
  • 6,024
  • 5
  • 35
  • 52
imthegiga
  • 1,126
  • 8
  • 13