0

If I remove the line indicated, the "elements" are displayed, although they are to big and go partly out of the screen, if I try to set the width and height (LayoutParams) of an element inside the tablerow, the tablelayout is displayed empty/blank. What am I doing wrong? Thank you.

Activity onCreate:

 TableLayout tLay = (TableLayout) findViewById(R.id.tabLay);
            LayoutInflater gonf = getLayoutInflater();
            for(int j= 0; j<rows;j++)
                {
                    TableRow tRow = new TableRow(this);
                    tRow.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            for (int i = 0; i<columns;i++)
                {
                    FrameLayout elVw = (FrameLayout) gonf.inflate(R.layout.elemento, null);
                    //elVw.setLayoutParams(new FrameLayout.LayoutParams(width/columns,height/rows));
                    elVw.setLayoutParams(new FrameLayout.LayoutParams(100,100));  //<------------------This Line---------
                    TextView tVw = (TextView) elVw.findViewById(R.id.txtVwDescr);


         Log.v("par",elVw.getLayoutParams().height+"");
                    elVw.setTag(i+","+j);

                    tVw.setText((String)elVw.getTag());

                    tRow.addView(elVw);

                }

                    tLay.addView(tRow);
                }

elemento.xml:

<FrameLayout

android:id="@+id/SingolFrame"
xmlns:android="http://schemas.android.com/apk/res/android"




    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
>


<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/txtVwDescr"
    android:padding="10dp"
    android:maxLength="30"
    android:maxLines="1"
    android:text="fn_High"
    android:background="#b7ffffff"
    android:paddingLeft="10dp"
    android:paddingTop="10dp"
    android:layout_margin="0dp"
    />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:id="@+id/imgGridIcon"
    android:focusable="false"

    android:contentDescription="Element"
    />

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:id="@+id/imgGridElementBorder"
    android:focusable="false"

    android:contentDescription="Element"
    android:background="@drawable/bordo_icona"/>

Stef
  • 45
  • 8

1 Answers1

0

I think you should use the parent viewGruop's layoutparams,maybe you can try use the TableLayout.LayoutParams(100,100) instead.

Alan W.
  • 4,566
  • 2
  • 15
  • 26
  • Ok, the correct parent was TableRow! So TableRow.LayoutParams. I found it here: [link](http://stackoverflow.com/questions/12684350/dynamically-created-tablerow-and-then-relativelayout-not-showing?rq=1) Thanks again! =) – Stef Oct 15 '15 at 19:29