How to add an Imageview to a Relativelayout on a runtimer?

Asked

Viewed 166 times

0

How do I add a ImageView at run time to LinearLayout or even a TableLayout?

1 answer

1

Both LinearLayout and TableLayout inherit from ViewGroup. The ViewGroup is the class that has the ability to aggregate and compose the hierarchy of View's.

In the case of LinearLayout just call addView passing his ImageView. It is optional to pass an index or a LayoutParams, you will be in charge of the situation.

In the case of TableLayout you will need to encompass your ImageView in a TableRow before and add the TableRow at the TableLayout.

One recommendation I give is to check the rules of layout_width and layout_height to use in LayoutParams of ImageView and/or the TableRow.

In the case of LinearLayout check the orientation to avoid problems.

  • great, that’s what I needed... obg.

  • @Herikr, if the answer helped you, mark it as right, so as not to confuse members thinking the answer is not useful.

  • It says that I need 15 points to vote in favour.

  • @Herik, just click on the green "arrow", indicating that this is the correct answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.