Forum Xamarin.Forms

How to Handle FontSize and control sizes across different screen resolutions and orientations?

HarivHariv INMember ✭✭
edited January 2018 in Xamarin.Forms

Hi, Need to set ui control sizes appropriate to various resolutions, suppose if image is having height and width 30 X 30 pixels in the design. for mentioning height and width requests in Xamarin.forms xaml, what is the units(pixels/dps) should be used to achieve the appropriate size across different resolutions/orientations.
Regarding FontSize, I followed the link, it seems it is not possible to integrate from the xaml. Is there any sample which handles the FontSize across different resolutions in xaml.

Any suggestions are welcome. Thanks in advance.

Harikrishna V

Best Answer


  • Umar3xUmar3x FRMember ✭✭✭


    You got the enum for that, which works great if you don't want to calculate your screen resolution on the fly.

    FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Need to set ui control sizes appropriate to various resolutions,

    My first response is always "Do you? Really do you need to? And why?" The nature of the ecosystem is that it already adjusts for you. All measureing is done in DiP (Device INDEPENDENT pixels). There are thousands of apps out there that look right on phone or tablet without having to micromanage such things. So what is your situation that you need to?

    Next you need to consider a lot more than just screen size and orientation. Are you also going to adjust for the scaling the user may have set at the OS level on their device? Bob might be 19 and have good eyes so he leaves the font size on the device to default. But Mark is 50 and half blind so he has fonts set to scale up 150%. Are you going to override the user's wishes... just ignore them... or are you going to take that into account enlarge your fonts as well?

    I'd suggest you build your UI in an agnostic, self-adjusting standard way like everyone else and worry more about functions working right than spending 7 hours a day micro-managing font sizes on every permutation of device and user setting.

  • HarivHariv INMember ✭✭
    @surajpandey.2234 my question is not about setting the fontsize based platform. My question is about setting the fontsize across different idems(phone/tablet). The fontsize 12units(24 pixels) looks good in iPhone 6 but on iPad Air 2 it will looks small. This problem I want overcome
    Without everything checking the for idem. Might be that's only the solution.
    @ClintStLaurent I agree with your suggestion. But better to have a solution if we can.
  • surajpandey.2234surajpandey.2234 USMember ✭✭
    edited January 2018

    Hi, @Hariv check it may be it will work.



    if (Xamarin.Forms.Device.Idiom == TargetIdiom.Phone)
    // apply phone only code
    mainGrid.Padding = new Thickness(10, 10, 10, 10);
    else if (Xamarin.Forms.Device.Idiom == TargetIdiom.Tablet)
    // apply tablet only code
    mainGrid.Padding = new Thickness(100, 10, 100, 10);

Sign In or Register to comment.