How to populate the TableLayout with ImageView dynamically in android jdk?

前端 未结 1 965
情话喂你
情话喂你 2021-01-16 04:45

I\'ve a TableLayout element in my main.xml:



        
相关标签:
1条回答
  • 2021-01-16 05:11

    Hope this helps.

                TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
                for (int r=1; r<=rowCount; r++){
                    TableRow tr = new TableRow(this);
                    for (int c=1; c<=columnCount; c++){
                        ImageView im = new ImageView (this);
                        im.setImageDrawable(getResources().getDrawable(R.drawable.image_name));
                        im.setPadding(0, 0, 0, 0); //padding in each image if needed
                        //add here on click event etc for each image...
                        //...
                        tr.addView(im, imageWidth,imageHeight); 
                    }
                    table.addView(tr);
                }
    
    0 讨论(0)
提交回复
热议问题