0

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.

1
  • Whereever you want to add any views dynamically just put a LinearLayout or RelativeLayout at that place and add the dynamically created views to that layout. In you example Relativelayout Commented Apr 25, 2014 at 9:11

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

Yes but if it's RelativeLayout then i need to tell RelativeLayout bellow button, and then my 'wanted' Layout below button.
Check this post. That explains very well. @user1730007
0

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); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.