Random Button Position Without Using an AbsoluteLayout

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Random Button Position Without Using an AbsoluteLayout

Postby tehbrosta » Tue Jan 05, 2010 9:25 pm

The application I am building requires a button to be randomly placed on the screen. I can easily do this using an AbsoluteLayout, but it's not going to work properly on all devices.


Any suggestions?

Edit: Or could I use an AbsoluteLayout and use getWidth() & getHeight() to see what my canvas size is?
tehbrosta
Freshman
Freshman
 
Posts: 6
Joined: Tue Jan 05, 2010 9:15 pm

Top

Postby jwei512 » Wed Jan 06, 2010 12:09 am

Maybe you're looking for something like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. WindowManager w = getWindowManager();
  3.  
  4. Display d = w.getDefaultDisplay();
  5.  
  6. int width = d.getWidth();
  7.  
  8. int height = d.getHeight();
  9.  
  10.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Which will give you the size of the screen for each machine? In which case you can randomize where your button is programmatically using these dimensions.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests