簡體   English   中英

Android-如何刪除表格布局及其中的所有圖像視圖?

[英]Android - How to remove table layout and and all imageviews in it?

這是我的代碼,可在運行時生成動態按鈕! 我已經嘗試了很多,但是無法刪除先前創建的動態按鈕!

這是代碼

TableLayout table = (TableLayout)findViewById(R.id.tableForButtons);
    TableRow tableRow = new TableRow (this);
    tableRow.setLayoutParams(new TableLayout.LayoutParams(
            TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT,1.0f
            ));
    table.setId(123);
    table.addView(tableRow);


    for(int i=0 ; i<ans_length; i++)
    {
        ImageView button = new ImageView (this);
        button.setLayoutParams(new TableRow.LayoutParams(
                TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT,1.0f
                ));
        button.setImageResource(R.drawable.a);
        button.setId(i);
        tableRow.addView(button);
    }

請為此提供幫助,並向我提供代碼,該代碼可能會刪除此表格布局及其所有視圖!!!

您需要調用.removeAllViewsInLayout(); 輸入要刪除的視圖的根布局。 因此,例如table.removeAllViewsInLayout(); 應該刪除所有行,但不會刪除表對象視圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM