android - how to avoid overlapping of dynamically positioned views -
how avoid overlapping of dynamically positioned views?
i have relativelayout , , adding views dynamically(at runtime) @ particular position(x,y coordinates) problem views overlapping. how avoid this.
thanks in advance.
<scrollview android:layout_width="fill_parent" android:layout_height="wrap_content" > <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <relativelayout android:id="@+id/rl_main" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > </relativelayout> <linearlayout android:layout_width="fill_parent" android:id="@+id/ll_mainbottom" android:layout_height="wrap_content" android:orientation="vertical" > </linearlayout> </linearlayout> </scrollview>
javacode
ll_main = (relativelayout) findviewbyid(r.id.rl_main); if (views[3].equals("textview")) { textview tv_new = new textview(tenminactivity.this); // location int x = integer.parseint(views[12]); int y = integer.parseint(views[13]); string bgcolor = "#" + views[4]; string fgcolor = "#" + views[5]; tv_new.setbackgroundcolor(color.parsecolor(bgcolor)); // bg color tv_new.settextcolor(color.parsecolor(fgcolor)); // text color relativelayout.layoutparams params = new relativelayout.layoutparams( width, android.view.viewgroup.layoutparams.wrap_content); params.leftmargin = x; params.topmargin = y; ll_main.addview(tv_new, params); }else if(views[3].equals("edittext")){ .... }
give
android:paddingleft=""
and each element ones left of screen have bit of space. , ones right,give
android:paddingbottom=""
first,check first 2 elements name text , text field after can proceed rest.
i can guide better,if post code
check this,
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" android:text="name" android:textsize="18sp" /> <edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbottom="@+id/textview1" android:layout_alignparenttop="true" android:layout_marginleft="21dp" android:layout_torightof="@+id/textview1" android:ems="10" android:padding="10dp" android:paddingl="10dp" > <requestfocus /> </edittext> </relativelayout>
Comments
Post a Comment