Layout problem: scrollview inside a table, inside a custom dialog

时光毁灭记忆、已成空白 提交于 2019-12-11 06:24:34

问题


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);
    }   
}

回答1:


Could you just use ListView with footer and header or it's a sample data and in fact you trying to do something more complex ?



来源:https://stackoverflow.com/questions/2900404/layout-problem-scrollview-inside-a-table-inside-a-custom-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!