How do I add a ImageView
at run time to LinearLayout
or even TableLayout
?
How do I add a ImageView
at run time to LinearLayout
or even TableLayout
?
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.