android - How to add Relative layout in Relative layout dynamically -
my project file has xml root xml. in root xml define relative layout below
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/root_view"> </relativelayout> i have xml file first one.xml , two.xml below
one.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" android:id="@+id/two_video_layout"> <textview android:id="@+id/two_video_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:singleline="true" android:text="video title" /> </relativelayout> and layout
two.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" android:id="@+id/two_video_layout"> <imageview android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </relativelayout> how can add one.xml or two.xml dynamically in root.xml condition , how can access reference of textview of one.xml file
you have add view using layoutparams.
linearlayout linearlayout = new linearlayout(this); relativelayout.layoutparams relativeparams = new relativelayout.layoutparams( layoutparams.fill_parent, layoutparams.fill_parent); relativeparams.addrule(relativelayout.align_parent_top); parentview.addview(linearlayout, relativeparams); to relatively position items programmatically have assign ids them.
textview tv1 = new textview(this); tv1.setid(1);
Comments
Post a Comment