Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 以编程方式将ImageView添加到tableLayout_Android_Android Layout - Fatal编程技术网

Android 以编程方式将ImageView添加到tableLayout

Android 以编程方式将ImageView添加到tableLayout,android,android-layout,Android,Android Layout,我有一个位图图像列表,如何以编程方式将此位图添加到tableLayout 谢谢。试试这样: TableLayout table = new TableLayout(this); for (int i = 0; i < mRows; i++) { TableRow tr = new TableRow(mContext); tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FIL

我有一个位图图像列表,如何以编程方式将此位图添加到tableLayout


谢谢。

试试这样:

    TableLayout table = new TableLayout(this);
    for (int i = 0; i < mRows; i++) {

        TableRow tr = new TableRow(mContext);
        tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        for (int j = 0; j < mCols; j++) {

            ImageView view = new ImageView(this);
            view.setImageResource(R.drawable.star_on)
            tr.addView(view);
        }
        table.addView(tr);
    }
TableLayout table=新的TableLayout(此);
对于(int i=0;i

这将以编程方式生成整个表/网格。您可以看到它是如何实例化ImageView和设置图像的。

尝试以下操作:

    TableLayout table = new TableLayout(this);
    for (int i = 0; i < mRows; i++) {

        TableRow tr = new TableRow(mContext);
        tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        for (int j = 0; j < mCols; j++) {

            ImageView view = new ImageView(this);
            view.setImageResource(R.drawable.star_on)
            tr.addView(view);
        }
        table.addView(tr);
    }
TableLayout table=新的TableLayout(此);
对于(int i=0;i

这将以编程方式生成整个表/网格。您可以看到它如何实例化ImageView并设置图像。

如何设置ImageView的宽度和高度?我想把它们做成32*32,但我做不到。怎么做?如何设置ImageView的宽度和高度?我想把它们做成32*32,但我做不到。怎么做?