java - Android - difference between static and dynamic button weight -
i'm working tablelayout, first row static (xml) , second row added during runtime. both layouts should visually equal. however, i'm getting different results:
row 1: [----a-----] [----------b----------] [-----c----] row 2: [-----a-----] [---------b---------] [-----c-----]
here xml row 1:
<button android:id="@+id/stat_a" android:layout_width="0dp" android:layout_weight="1" android:text="a" />
the weight "1" buttons stat_a , stat_c, , "2" stat_b.
here java code row 2:
button btn = new button(this); btn.setid("dyn_a"); layoutparams btn_param = new tablerow.layoutparams(layoutparams.match_parent, layoutparams.match_parent, _dyn_weight_); btn.setlayoutparams(btn_param); btn.settext("a"); layout.addview(btn);
the _dyn_weight_ "1" buttons dyn_a , dyn_c, , "2" dyn_b.
where mistake?
thanks!
edit
the full xml:
<tablelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tbl01" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".mainactivity"> <tablerow android:id="@+id/row1" android:layout_width="match_parent" android:layout_height="match_parent"> <button android:id="@+id/stat_a" android:layout_width="0dp" android:layout_weight="1" android:text="a" /> <button android:id="@+id/stat_b" android:layout_width="0dp" android:layout_weight="2" android:text="b" /> <button android:id="@+id/stat_c" android:layout_width="0dp" android:layout_weight="1" android:text="c" /> </tablerow> <tablerow android:id="@+id/row2" android:layout_width="match_parent" android:layout_height="match_parent"> </tablerow> </tablelayout>
Comments
Post a Comment