Can't add RelativeLayout programmatically in android -
i have xml layout file.this xml layout source code
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" > <relativelayout android:id="@+id/rot" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:background="#ff0000" > <imageview android:id="@+id/btn_categorry" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_alignparenttop="true" android:layout_marginright="12dp" android:background="@drawable/ic_launcher" /> </relativelayout>
i try add new relativelayout programmatically,bellow 'rot' layout.i wrote code can't add new layout source
img.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { relativelayout.layoutparams parms = new relativelayout.layoutparams( relativelayout.layoutparams.fill_parent, relativelayout.layoutparams.wrap_content); final relativelayout ll = new relativelayout( getapplicationcontext()); button add_btn = new button(getapplicationcontext()); add_btn.settext("click add textviiews , edittexts"); ll.addview(add_btn); parms.addrule(relativelayout.below, r.id.rot); ll.setlayoutparams(parms); } });
as said can't add layout.what doing wrong? if knows solution please me thanks
create object of main relative layout.
relativelayout main = (relativelayout)findviewbyid(r.id.mainrelativelayout); main.addview(ll);
add above code after ll.setlayoutparams(parms);
Comments
Post a Comment