【问题标题】:setLayoutParams of FrameLayout in tableRow element / view not showingtableRow 元素/视图中 FrameLayout 的 setLayoutParams 未显示
【发布时间】:2016-01-11 07:05:45
【问题描述】:

如果我删除指示的行,“元素”会显示出来,尽管它们很大并且部分超出了屏幕, 如果我尝试设置 tablerow 内元素的宽度和高度 (LayoutParams),则 tablelayout 显示为空/空白。 我究竟做错了什么? 谢谢。

创建活动:

 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"/>

【问题讨论】:

    标签: android android-tablelayout tablerow android-framelayout layoutparams


    【解决方案1】:

    我认为你应该使用父 viewGruop 的 layoutparams,也许你可以尝试使用 TableLayout.LayoutParams(100,100) 代替。

    【讨论】:

    • 好的,正确的父级是 TableRow!所以 TableRow.LayoutParams。我在这里找到它:link 再次感谢! =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多