views:

383

answers:

1

I have a layout problem which I can't fix. I've looked through many posts on here, and mine seems to be unique enough to post a question.

I've created a custom Dialog which programmatically creates a 3 row table. The top and bottom rows have text, while the middle row contains a ScrollView, which contains a LinearLayout. That LinearLayout then contains some number of views (TextView in this example). Since I'm doing this programmatically, see the XML pseudocode below, and the actual code below that.

What I would like to happen, is that when the height of the contained content in the LinearLayout gets too big, the ScrollView does its job, and the header and footer TextView's are always visible.

The problem is that when the dialog gets big enough, the ScrollView appears to take over the whole dialog, and my footer TextView disappears off the screen. What can I do to make sure the footer TextView never disappears, but the ScrollView can still function?

See the following image links:

Footer visible on the left, gone on the right:

http://img690.imageshack.us/i/screenshotss.png/

<TableLayout>
    <TableRow>
        <TextView>
    </TableRow>
    <TableRow>
        <ScrollView>
            <LinearLayout>
                <TextView/>
                <TextView/>
                <TextView/>
                ...
            </LinearLayout>
        </ScrollView>
    </TableRow>
    <TableRow>
        <TextView>
    </TableRow>
</TableLayout>

Here's the code:

public class DialogScrollTest extends Dialog {

    public DialogScrollTest(Context ctx){
        super(ctx);

        setTitle("");
        requestWindowFeature(Window.FEATURE_NO_TITLE); 

        TableLayout table = new TableLayout(ctx);       
        TableRow row;       
        TextView text;

        row = new TableRow(ctx);
        {
            text = new TextView(ctx);
            text.setText("TestTop");
            row.addView(text);
        }
        table.addView(row);

        row = new TableRow(ctx);
        {
            ScrollView scroll = new ScrollView(ctx);
            {   
                LinearLayout linear = new LinearLayout(ctx);
                linear.setOrientation(LinearLayout.VERTICAL);
                for(int t=0; t<32; ++t){
                    text = new TextView(ctx);
                    text.setText("TestScroll");
                    linear.addView(text);                   
                }
                scroll.addView(linear);
            }       
            row.addView(scroll);
        }
        table.addView(row);

        row = new TableRow(ctx);
        {
            text = new TextView(ctx);
            text.setText("TestBottom");
            row.addView(text);
        }
        table.addView(row);

        this.setContentView(table);
    }   
}
+1  A: 

Could you just use ListView with footer and header or it's a sample data and in fact you trying to do something more complex ?

Alex Volovoy
The TextView objects in the ScrollView are just samples -- the actual interface I want to use is quite arbitrary. So, it doesn't really lend itself well to a ListView and adapter.I wish there was some way to communicate to the middle TableRow that it's maximum size is limited by not forcing the bottom TableRow off the Dialog, and then the ScrollView would have to settle for the remaining space. Does anyone know the proper way to set this contraint?
Sean
Also, I can use a RelativeLayout to make this work when the ScrollView contains more than a page of content. But, when that content is only a few lines, the ScrollView doesn't shrink to wrap the contents. This is in spite of WRAP being set on it. I guess the RelativeLayout takes precedence. This is frustrating.
Sean
I still have a feeling that ListView could be a good choice if you have items that use same layout( even if it's a complex one). But i can't answer the tablerow question without trying it myself. sorry ...
Alex Volovoy