How to dynamically add views to custom layout based on size

by Brent Edwards » Sun, 29 Nov 2009 04:21:06 GMT

Sponsored Links
 I have created a custom GameBoard class which derives from
TableLayout.  I have also a created custom GamePiece class to be
placed on this game board that derive from ImageView.  My goal is to
measure the size of the GameBoard and dynamically add a variable
number GamePieces based on the size of the GameBoard.

To accomplish this, I have overridden onSizeChanged in GameBoard to
determine the size of the board and I calculate how many GamePieces to
place based on this width and height.  I have log messages that output
whenever a GamePiece is added to the GameBoard (via addView).  Though
I can see the messages coming through, I never see the GamePieces.

I have found through testing that I can place a fixed number of
GamePieces (which are visible) on the GameBoard in the GameBoard's
constructor, but I cannot know it's dimension at that time.

I have also tried adding the GamePieces in the onLayout method, but
get the same results as onSizeChanged.

What is the correct method for determining the size of my GameBoard
and placing a variable number of GamePieces based on that size?

Thanks in advance,


Other Threads

1. current mydroid cannot play video or camera

i have sync to latest mydroid
but it turned out in my build (on emulator)
video cannot be played
camera cannot work

is there something wrong in current mydroid?



2. Orange experts are answering your questions Live at LeWeb

Do you want to know more about apps submission process at Orange?
About testing? About the new on-device App Shop client Orange just
launched yesterday at LeWeb?

Join the online community and ask them questions


3. How to call a view from the view ?

4. Where can I catch a point that is assured to be called when a Service is destroied

5. How to keep mobile network alive even if screen is off

6. Busy Coders Guide is 拢204/$24 0 on Amazon...

7. <WTA> force close dream...