evan
evan

Reputation: 1118

android layout form activity

i am having an xml main.xml,which has few layouts

<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/mainl"
   android:tag="aa"
   android:orientation="vertical"
   android:layout_height="wrap_content"
   android:layout_width="fill_parent">

</LinearLayout>

Is it possible to add one more layout inside the LinearLayout from the Activity at Run time. I am able to create Layout in Activity(without using xml) ,but problem in adding this layout to xml at run time ,anyone has a solution

Upvotes: 1

Views: 866

Answers (2)

Kakey
Kakey

Reputation: 4024

use the following code

LinearLayout parent,child;

child=new LinearLayout(this);

parent=(LinearLayout)findviewById(R.id.mainl);

LinearLayout.LayoutParams lp = new   LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,   LinearLayout.LayoutParams.FILL_PARENT);

parent.addView(child,lp);

Upvotes: 2

Jean
Jean

Reputation: 10600

You won't add it to the XML at run-time, but you can add it to the layout, which I think is what you want to do.

parent.addView(child);

Upvotes: 2

Related Questions