Reputation: 8467
If I have a ImageView
foo
I can modify its parameters before adding it to a Layout with:
RelativeLayout.LayoutParams testParams = new RelativeLayout.LayoutParams(500,500);
foo.setLayoutParams(testParams);
then I add foo
to the layout with:
exampleLayout.addView(foo);
How can I modify the parameters after adding foo
to the layout? (I read that there was a different process if foo
was already added to the layout)
Upvotes: 2
Views: 69
Reputation: 1644
Try to modify layout parameters before adding to its parent, but if you want to modify it, first find it by its ID, then use getLayoutParams()
method and modify it, then set it again using setLayoutParams()
.
Upvotes: 0
Reputation: 726
You can still edit after adding the foo.
on your foo add the id at runtime. Lets say. foo.setId(23);
now at runtime examplelayout.findviewbyid(23)
will give you your view.
Now you can update params on that. and call invalidate()
Upvotes: 2