Layout problem: scrollview inside a table, inside a custom dialog
- by Sean
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);
}
}