android - Add a dynamic tablelayout in a relativelayout above a existing button -
i'm trying add tablelayout in relativelayout, i'm havind problems put tablelayout above existing button, can below it.
xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:stretchcolumns="0,1" tools:context=".mainactivity" > <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="button" />
the lp.addrule(relativelayout.above, idx); isn't working
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // size of screen set size of buttons according // level display display = getwindowmanager().getdefaultdisplay(); point size = new point(); display.getsize(size); int level = 3; int width = size.x - (size.x / level); int btsize = width / level; // main layout relativelayout rlayout = (relativelayout) findviewbyid(r.id.main); // tablelayout tlayout = new tablelayout(this); int id = 0; (int = 0; < level; i++) { // create tablerow tablerow trow = new tablerow(this); (int j = 0; j < level; j++) { id++; button bt = new button(this); bt.setid(id); bt.setwidth(btsize); bt.setheight(btsize); bt.setminimumwidth(0); bt.setminimumheight(0); trow.addview(bt); // add button row } tlayout.addview(trow);// add row table } relativelayout.layoutparams lp = new relativelayout.layoutparams( relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content); int idx = findviewbyid(r.id.button1).getid(); lp.addrule(relativelayout.above, idx); rlayout.addview(tlayout,lp);// add table relativelayout }
you can try this... put code in oncreate() method
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); relay = (relativelayout)findviewbyid(r.id.rlayout); layoutparams layoutprams = new layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); tablelayout table=new tablelayout(this); relay.addview(table);
Comments
Post a Comment