【发布时间】:2010-05-25 05:22:03
【问题描述】:
我有一个无法解决的布局问题。我在这里浏览了很多帖子,我的帖子似乎很独特,可以发布一个问题。
我创建了一个自定义对话框,它以编程方式创建一个 3 行表。顶行和底行有文本,而中间行包含一个 ScrollView,其中包含一个 LinearLayout。然后,LinearLayout 包含一些视图(本例中为 TextView)。由于我以编程方式执行此操作,请参阅下面的 XML 伪代码,以及下面的实际代码。
我想要发生的是,当 LinearLayout 中包含的内容的高度变得太大时,ScrollView 会完成它的工作,并且页眉和页脚 TextView 始终可见。
问题是当对话框变得足够大时,ScrollView 似乎接管了整个对话框,而我的页脚 TextView 从屏幕上消失了。 我该怎么做才能确保页脚 TextView 永远不会消失,但 ScrollView 仍然可以运行?
查看以下图片链接:
页脚在左侧可见,在右侧消失:
http://img690.imageshack.us/i/screenshotss.png/
<TableLayout>
<TableRow>
<TextView>
</TableRow>
<TableRow>
<ScrollView>
<LinearLayout>
<TextView/>
<TextView/>
<TextView/>
...
</LinearLayout>
</ScrollView>
</TableRow>
<TableRow>
<TextView>
</TableRow>
</TableLayout>
代码如下:
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);
}
}
【问题讨论】: