Search code examples
androidandroid-layoutandroid-viewandroid-scrollviewandroid-tablelayout

Is my proposed layout sensible, or at least "doable"?


I need to have a "fixed row" with a scrolling area below it filled with 1..N rows of dynamically created widgets/views. Here is what I am hoping will work (pseudo-xml):

<LinearLayout llv (vertical)>

    <TableLayout tlFixedRow > <-- child of llv, sibling of sv
        <TableRow 
            <TextView "Blee"/>
            <TextView "Bla"/>
            <TextView "Bloo"/>
            <TextView "Bligh"/>
        <TableRow /> 
    </TableLayout>

    <ScrollView sv > <-- child of llv, sibling of tlFixedRow
        <TableLayout tlDynamicRowsParent >
            <TableRow /> <-- 0..N TableRows, added dynamically
        </ TableLayout >

    </ ScrollView sv>

</LinearLayout llv>

So the layout file is:

<LinearLayout llv (vertical)>

    <TableLayout tlFixedRow > <-- child of llv
        <TableRow 
            <Checkbox/>
            <Checkbox/>
            <Checkbox/>
            <TextView "Bla"/>
        <TableRow /> 
    </TableLayout>

    <ScrollView sv > <-- child of llv, sibling of tlFixedRow
        <TableLayout tlDynamicRowsParent >

        </ TableLayout >

    </ ScrollView sv>    

</LinearLayout llv>

...and the TableRows (after the first, fixed one) are added dynamically, represented by this pseudocode:

TableLayout tlDynamic = (TableLayout)findViewById(R.id.tlDynamicRowsParent);
...
for i = 0 until theCowsComeHome() do {
Checkbox ckbx1 = new Checkbox();
Checkbox ckbx1 = new Checkbox();
Checkbox ckbx1 = new Checkbox();
TextView txtView = new txtView();
// ... (set some of the Checkbox and textView properties)

TableRow tr = new TableRow();
tlDynamicRowsParent.addView(tr);
tr.addView(ckbx1);
tr.addView(ckbx2);
tr.addView(ckbx3);
tr.addView(txtView);
}

Thus and verily, my assumptions are:

LinearLayout can have 0..N of children; ScrollView can have only one child; TableLayout can have 0..N TableRows.

Are my assumptions valid, or did I make a sump out of ions?


Solution

  • Yes, everything you assumed is correct. You practically have it all coded up / XML done so you could have just tried it :) Although, you are adding 3 checkboxes and a textview to your dynamic table layout when you have the same exact controls already marked up in XML in the fixed table row. I'm not sure if this is intentional or not.