1

I've been playing with centering a panel on a device screen. I've tried a few things but cant get the syntax/math correct. I am adding the panel with it's size relative to the screen size as below (80% width and 40% height). At the moment I left the x,y location at 0,0 - Any suggestions on correct syntax to center on screen are appreciated!

Activity.AddView(quitsavepnl,0,0, 80%x, 40%y)
Tony Moreira
  • 93
  • 3
  • 18

2 Answers2

3

Here:

Activity.AddView(quitsavepnl, 50%x - 80%x / 2, 50%y - 40%y / 2, 80%x, 40%y) 
Erel
  • 1,802
  • 2
  • 15
  • 58
  • Thank you. That did it perfectly. I was using something similar I saw in a thread at b4a, but the math was working right. – Tony Moreira Oct 23 '11 at 11:11
1

You can get DisplayMetrics to get device screen and add it in the center of device screen if you want it.

Or if you want to display View in the center of parent View use CENTER_IN_PARENT, which is available in RelativeLayout

Pete Houston
  • 14,931
  • 6
  • 47
  • 60