0

I would like to create a table of values, the table will have 2 columns, and N rows. The first row of the table will contain the headings, for example, "Height" and "Width", but I need these to be buttons. The next rows in the table will just contain text values, underneath their 'Height' and 'Width' headings, and these are populated using a class that extends BaseAdapter.

I don't know how to align the contents of the table to be aligned to the left edge of each heading button?

Currently I have something like this, but maybe I should be using a GridView? Or TableView?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    <Button android:text="Height" 
            android:layout_height="wrap_content" 
            android:id="@+id/buttonHeight" 
            android:layout_width="wrap_content"
            android:layout_weight="15">
    </Button>
    <Button 
            android:text="Width" 
            android:layout_height="wrap_content" 
            android:id="@+id/buttonWidth" 
            android:layout_width="wrap_content"
            android:layout_toRightOf="@id/buttonHeight"
            android:layout_weight="1">
    </Button>
     </LinearLayout>
     <ListView android:id="@android:id/list"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     android:dividerHeight="1px"
     android:drawSelectorOnTop="false"/>
</RelativeLayout>

Then my BaseAdapter inflates the following xml in order to assign the 'height' and 'width' to fill in all the row values, inside the overridden getView method:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
    android:layout_height="wrap_content">
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/height" 
    android:textSize="10sp"
    android:text="Height"
    android:layout_weight="1"/>       
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/width" 
    android:textSize="10sp"
    android:text="Width"
    android:layout_weight="1"/>
</LinearLayout>

Unfortunately the data simply does not line up with the button edges. How can I acheive this?

lost_bits1110
  • 157
  • 1
  • 5
  • 18
  • Okay, I figured it out using the current approach. I had to make use of android:layout_gravity="left" for all the buttons and textviews in order to make sure everything was left aligned, as well as android:layout_width="fill_parent" for the layout_gravity to take effect. This made things look much better, though the text was still slightly off from the the buttons. I'm not sure why, but I was able to simply add android:paddingLeft to take care of this. – lost_bits1110 May 25 '11 at 23:21
  • You might consider using a TableLayout. – Cheryl Simon May 26 '11 at 00:23
  • Thanks, I had already tried this, but my rows were no longer being populated with data using the BaseAdapter class. – lost_bits1110 May 26 '11 at 17:01
  • You might want to take a look at http://stackoverflow.com/questions/5459168/the-question-asked-100-000-times-how-does-one-create-buttons-with-equal-widths and http://stackoverflow.com/questions/5509494/wanted-tablelayout-like-listview. – Thane Anthem May 26 '11 at 01:26

0 Answers0