0

I am making an application that need to have layout items loaded dynamic. I have an XML where I have the design of the element that will be added multiple times on the stage. Also, I have a RelativeLayout that will hold the elements. To add an element to the RelativeLayout I use this:

...   
View child = View.inflate(context, R.layout.buildinglayout, null);
parrent.addView(child, parrent.getChildCount()); //parrent is the relativeLayout
...

As you may guessed, buildinglayout.xml is the layout of the element. Everything is added to the stage correctly and apparently with no problems. The thing is that the element's to fit on the stage so I need to have a ScrollView that surrounds the RelativeLayout. The only problem is that the scrollview does not detect the actual width and height of the RelativeLayout. So...I did this:

...
View child = View.inflate(context, R.layout.buildinglayout, null);
parrent.addView(child, parrent.getChildCount()); //parrent is the relativeLayout
Log.v("BuildingView", "w:" + child.getWidth() + " h:" + child.getHeight());
Log.v("ParrentView", "w:" + parrent.getWidth() + " h:" + parrent.getHeight());
...

The output of those Log.v is:

03-29 06:56:43.803: VERBOSE/BuildingView(480): w:0 h:0
03-29 06:56:43.803: VERBOSE/ParrentView(480): w:0 h:752

Can anyone please tell me what to do so that the width and height of both the buildingview and the parrent to be corect?

P.S. I am using Android 3.0 on an emulator device

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Petre Popescu
  • 1,950
  • 3
  • 24
  • 38

2 Answers2

0

The view that is added in UI thread will reflect after UI thread completes.

Try to find width after UI thread completes.

Then only it will give actual width and height.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Ganapathy C
  • 5,989
  • 5
  • 42
  • 75
  • The thing is that I don't really need the actual width and height. I only need the ScrollView to update accordingly to the width and height of the elements. The elements have a total height of about 850px and are clearly cut...but no scroll bar appears to let me scroll down. – Petre Popescu Mar 29 '11 at 08:01
0

The inflate is ignoring the layout height and width specified in the xml. Either set the layout params of child view or check this answer on how to inflate the view.

Community
  • 1
  • 1
Karan
  • 12,724
  • 6
  • 40
  • 33
  • OK! I found the problem. child.setX(pozX); and child.setY(pozY); make everything run in a strange way. The thing is I don't know any other way to set coordinates to an item inside a relativelayout – Petre Popescu Mar 31 '11 at 08:32