Test
Test

Reputation: 45

How to get mobile sreen size with Xamarin C#?

I want to make my application responsive, so I need the size of the screen, but I can't find any code. Does anyone know the code for the size of the screen?

Upvotes: 2

Views: 665

Answers (1)

SushiHangover
SushiHangover

Reputation: 74094

For Xamarin.Android:

var x = Resources.DisplayMetrics.WidthPixels;
var y = Resources.DisplayMetrics.HeightPixels;

Xamarin also has an Android sample app: Detect Screen Size

For Xamarin.iOS:

var x = UIScreen.MainScreen.CurrentMode.Size.Width;
var y = UIScreen.MainScreen.CurrentMode.Size.Height;

Upvotes: 3

Related Questions