我有一个布局问题,我无法修复。我浏览过这里的很多帖子,而且我的帖子似乎很独特,可以发表一个问题。布局问题:在自定义对话框中的表格内滚动视图
我创建了一个自定义对话框,它以编程方式创建一个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);
}
}
ScrollView中的TextView对象只是样本 - 我想要使用的实际接口是非常随意的。所以,它并不能很好地适用于ListView和适配器。 我希望有一些方法可以与中间TableRow进行通信,它的最大尺寸受限于不会强制关闭对话框的底部TableRow,然后ScrollView将不得不解决剩余空间问题。有没有人知道设置这种限制的正确方法? – Sean 2010-05-25 15:40:40
此外,当ScrollView包含多个内容页面时,我可以使用RelativeLayout使其工作。但是,当内容只有几行时,ScrollView不会缩小以包装内容。尽管已经设置了WRAP,但这仍然是个问题。我猜RelativeLayout优先。这令人沮丧。 – Sean 2010-05-25 23:12:37
我仍然有一种感觉,即如果您的项目使用相同的布局(即使它是一个复杂的),ListView可能是一个不错的选择。但是我不能自己回答这个问题。对不起... – 2010-05-26 16:42:43