user1730007
user1730007

Reputation: 211

Dynamically add Layout after some layout?

For example

<LinearLayout>

   <TextView />
   <ImageView />

   <Button />
   <RelativeLayout />
   <ImageView/>

</LinearLayout>

Now how to add dynamicly Layout after Button?

If i get first (root) Layout and i addView() adds in the end.

Upvotes: 0

Views: 62

Answers (3)

sona
sona

Reputation: 31

You can use intent on the click event of your button , in order to navigate between the different layouts

Intent i= new Intent((your class).this,(layout class that you want).class);
start Activity(i); 

Upvotes: 0

laalto
laalto

Reputation: 152847

Add an empty LinearLayout where you want your views placed dynamically, and add the views to that layout.

Upvotes: 1

MysticMagicϡ
MysticMagicϡ

Reputation: 28823

You can do that using RelativeLayout as parent layout.

Xml:

<RelativeLayout>

   <TextView />
   <ImageView />

   <Button />
   <RelativeLayout />
   <ImageView/>

</RelativeLayout>

Java:

RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT);

param.addRule(RelativeLayout.BELOW, R.id.existing_layout);

newView.setLayoutParams(param);

Hope this helps.

Upvotes: 0

Related Questions