gpt4 book ai didi

android - 自定义对话框内的布局问题 : scrollview inside a table,

转载 作者:行者123 更新时间:2023-11-30 04:52:21 25 4
gpt4 key购买 nike

我有一个无法修复的布局问题。我浏览了这里的许多帖子,我的帖子似乎很独特,可以提出问题。

我创建了一个自定义对话框,它以编程方式创建一个 3 行表。顶行和底行有文本,而中间行包含一个 ScrollView,它包含一个 LinearLayout。该 LinearLayout 然后包含一些 View (本例中为 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);
}
}

最佳答案

您能否仅将 ListView 与页脚和页眉一起使用,或者它只是一个示例数据,而实际上您正在尝试做一些更复杂的事情?

关于android - 自定义对话框内的布局问题 : scrollview inside a table,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2900404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com