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. Aplikasi mencatat pemakaian data

Baru 10 hari pake layanan unlimited TelkomSel tapi usage 500mb dah 
abis......waduh komplain ke TelkomSel mereka nga punya pencatatan pemakaian 
data pelanggan daripada berdebat mendingan cari apk buat nyatet aja 
deh.......ada yang tau?

"Indonesian Android Community [id-android]" 

2. Singapura --- Xperia X8

Saya pilih yang pertama pak...
Nocan please...


-----Original Message-----
From: "Herry SW" <>
Date: Wed, 16 Jun 2010 08:38:59 
Subject: [id-android] Singapura --- Xperia X8

Manakah yang paling menarik? :)


"Indonesian Android Community [id-android]" 

3. Fix for OutofMemoryError: bitmap size exceeds VM budget

4. OnOrientationChanged leaks in ListView

5. how to change colours in a .xml defined layout in run time

6. Problem in getting scroll position in web-view

7. Problem in getting scroll position in web-view