How to add an ImageView in a RelativeLayout in runtimer?

0

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

    
asked by anonymous 11.10.2014 / 16:10

1 answer

1

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

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

For TableLayout you will need to enclose your ImageView in TableRow before adding TableRow to TableLayout .

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

In case of LinearLayout check the orientation to avoid problems.

    
11.10.2014 / 16:35