Android TableLayout question: get a fixed-width right column?

10,525

Any thoughts?

First, why are you using a TableLayout? Why not just use nested LinearLayouts? You've already decided you don't care about the primary use for a TableLayout -- automatic computation of column sizes -- because you're trying to fix the column sizes yourself.

Second, can you get it working using an ordinary widget for the right column, rather than your custom View class? Your problem may be due to your custom View -- I'd start by getting something working the way you want using ordinary widgets.

Share:
10,525
Epaga
Author by

Epaga

Java developer @ i-net software by day Indie iOS developer of Mindscope and In-Flight Assistant by night Husband of 1, dad of 4

Updated on June 04, 2022

Comments

  • Epaga
    Epaga almost 2 years

    (Edited: I'm one step further than before)

    I've been trying to get a simple 2-column TableLayout going where I have a LinearLayout in my left column that I dynamically add elements to which fills up the horizontal space except for the fixed 100px right column.

    Here's what I have so far which works for me IF the LinearLayout contains more than one element. If it contains only one element, the right column is pushed out to the right of the screen

     <ScrollView android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@layout/main">
      <TableLayout android:layout_width="fill_parent"
                   android:layout_height="fill_parent">
         <TableRow>
           <LinearLayout android:id="@+id/LinearLayout01"
                             android:layout_width="fill_parent"
                             android:layout_height="fill_parent" 
                             android:layout_weight="0.4"
                             android:orientation="vertical"></LinearLayout>
        <com.epaga.ArcDrawableView 
                             android:layout_width="fill_parent" 
                             android:layout_height="fill_parent" 
                             android:gravity="right" android:layout_weight="0.1" >
           </com.epaga.ArcDrawableView>
         </TableRow>
       </TableLayout>
     </ScrollView>
    

    Things I've tried:

    • changing the drawable view (which is supposed to be the fixed column) to android:layout_width="150px"
    • changing the stretchcolumns setting to 0.
    • changing the left columns' layout_width to either fill_parent (pushes the right column off the screen) or wrap_content (collapses the left column)

    Any thoughts?