In Android when I am adding a view object like ImageView to FrameLayout view and then immediately trying to call layout()
method to repositioned the added view object
it is not working. But when I call the layout method alone after some new event e.g. touch event then layout() seems to work. This also happens when bringToFront() and layout() is used together, layout() does not seems to work together with other method. Is there any reason why is this like this? Also instead of adding view object in the middle of the screen can it be ADDED at some specific location in FrameLayout?
Asked
Active
Viewed 2,245 times
1

hasanghaforian
- 13,858
- 11
- 76
- 167

ravi
- 391
- 4
- 12
2 Answers
4
You should NEVER call layout() directly. This is used by the framework only. You must modify the View's layout params (getLayoutParams()) and call requestLayout().

Romain Guy
- 97,993
- 18
- 219
- 200
-
im setting layout params of my layout but in onCreate but all the childs view gets invisible?? – Muhammad Babar Apr 08 '13 at 10:41
-
and what is the best time to set Layout Params?? – Muhammad Babar Apr 08 '13 at 10:42
1
try this:
FrameLayout.LayoutParams layout = new frameLayout.LayoutParams (LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,Gravity.BOTTOM);

Viraj
- 1,880
- 22
- 31

LoveBigPizza
- 41
- 1