android - Dynamically created button not fill the parent -
i creating table row dynamically in android , creating button in row. rendering fine created button fills parent, i.e. occupies full width of parent row. want fixed width array i.e. 150px.
my code
tablerow rows = new tablerow(this); tablelayout.layoutparams tablerowparamss= new tablelayout.layoutparams (tablelayout.layoutparams.fill_parent,tablelayout.layoutparams.wrap_content); rows.setbackgroundcolor(color.parsecolor("#62b0ff")); tablerowparamss.setmargins(0, 0, 0, 40); rows.setlayoutparams(tablerowparamss); button ib = new button(this); //ib.setbackgroundresource(r.drawable.accept); final float scale = getresources().getdisplaymetrics().density; int heightdp = (int) (33 * scale + 0.5f); int widthdp = (int) (60 * scale + 0.5f); viewgroup.layoutparams blp = new viewgroup.layoutparams(widthdp,heightdp); rows.addview(ib); table.addview(rows);
how can make button width fixed 150px , align right side of row?
import tablerowparam // import android.widget.tablerow.layoutparams; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.text); tablelayout table = (tablelayout) findviewbyid(r.id.tablelayout1); tablerow rows = new tablerow(this); tablelayout.layoutparams tablerowparamss= new tablelayout.layoutparams (tablelayout.layoutparams.fill_parent,tablelayout.layoutparams.wrap_content); rows.setbackgroundcolor(color.parsecolor("#62b0ff")); tablerowparamss.setmargins(0, 0, 0, 40); rows.setlayoutparams(tablerowparamss); button ib = new button(this); //ib.setbackgroundresource(r.drawable.accept); // import android.widget.tablerow.layoutparams; layoutparams rowparam = new layoutparams(150, layoutparams.wrap_content); ib.setlayoutparams(rowparam); rows.addview(ib); table.addview(rows); } <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <tablelayout android:id="@+id/tablelayout1" android:layout_width="match_parent" android:layout_height="wrap_content" > </tablelayout> </linearlayout>
Comments
Post a Comment