布局问题:在自定义对话框内的表内滚动视图

时间:2010-05-24 21:17:36

标签: android android-widget

我有一个无法解决的布局问题。我在这里查看过很多帖子,而且我的帖子似乎很独特,可以发帖提问。

我创建了一个自定义Dialog,它以编程方式创建一个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);
    }   
}

1 个答案:

答案 0 :(得分:1)

你可以将ListView与页脚和标题一起使用,或者它是一个示例数据,实际上你试图做一些更复杂的事情吗?