0

setLayoutParams如果我刪除指示的行,將顯示「元素」,儘管它們很大並且部分偏離屏幕,如果我嘗試設置寬度和高度(LayoutParams),tablelayout顯示爲空白/空白。 我在做什麼錯? 謝謝。setLayoutParams在TableRow元素/視圖中沒有顯示

活動的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"/> 

+0

難道這麼難嗎? – Stef

回答

0

我認爲你應該使用父viewGruop的的LayoutParams,也許你可以嘗試使用TableLayout.LayoutParams(100,100 )代替。

+0

我試過了,但不起作用。不管怎樣,謝謝你! – Stef

+0

好吧,正確的父母是TableRow!所以TableRow.LayoutParams。我發現它在這裏:[鏈接](http://stackoverflow.com/questions/12684350/dynamically-created-tablerow-and-then-relativelayout-not-showing?rq=1)再次感謝! =) – Stef

+0

不客氣!現在我知道,以及(^▽^)o –