android - Fail to Move a View to a TableRow -


i trying inflate layout resource , move views in table. remove views parents , add them table. works need add them tablerow in table instead. however, when tried that, nothing showed up.

to simplify example, use views in xml instead of ones generated in code. in following xml, there tablelayout 1 tablerow , imagebutton:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     ...>          <tablelayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/table">          <tablerow             android:layout_width="match_parent"             android:layout_height="match_parent"             android:id="@+id/row_1"></tablerow>     </tablelayout>  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="new button"     android:id="@+id/button" />  </relativelayout> 

if move button table, works:

button button = (button ) getactivity().findviewbyid(r.id.button); tablelayout table = (tablelayout) getactivity().findviewbyid(r.id.table); tablerow row  = (tablerow) getactivity().findviewbyid(r.id.row_1);  ((viewgroup)button.getparent()).removeview(button); table.addview(button); 

however, if move tablerow, button won't show up.

row.addview(button); 

does have solution?

try add button row this:

   row.addview(button,new tablerow.layoutparams(                tablerow.layoutparams.wrap_content,                tablerow.layoutparams.wrap_content)); 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -