开发者

Android: addView and layout method does not work together

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.开发者_StackOverflow社区 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?


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().


try this:

FrameLayout.LayoutParams layout = new frameLayout.LayoutParams (LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,Gravity.BOTTOM);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜