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

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -