Resolution-dependent font size

I am a Xamarin newbie and struggling with my first application
It shows an image with an entry view on top of it. The image serves as background for the entry. I place the entry on top of the image so it looks like the image is the entry. This works basically fine but when I look at the app on a different device with a different resolution the font size of the entry is way too big.

I tried to set the font size dynamically in the Android code as described here: http://developer.xamarin.com/recipes/android/resources/device_specific/detect_screen_size/

But this still doesn't give the result I want. Neither does a percent definition as in RelativeLayout.

I just want my font size to stay the same relative to the screen size so the entry is always within the background image borders.

I hope anybody can help me with this or give me a hint for a workaround.

Tagged:

Best Answer

Answers

  • adamkempadamkemp mod USInsider, Developer Group Leader mod

    The font size is already device-independent on Android. It sounds like the problem is your image. You should have multiple resolutions for your image. On Android that is done by putting the various different resolutions in the different "drawable" directories, like "drawable-mdpi" and "drawable-hdpi". See this page. When you do that right the physical image size on screen should scale in a similar way to the font size.

  • RicoWidmerRicoWidmer ✭✭ USMember ✭✭

    Thank you for your fast response. Your hint with the image is important. I as well figured out that I should use "sp" or "dp" instead of "pt" as unit.
    When I use "pt" the font is really small on big screens and big on small screens. When I use "sp" or "dp" it looks like the font is about the same size on big and small screens.
    But how can I achieve that the font is smaller on small devices and bigger on big devices?

  • adamkempadamkemp mod USInsider, Developer Group Leader mod

    The dp unit is used to make the real size vary by pixel density. There's no unit that I know of for fonts to vary by screen resolution. I don't see why you would need that here.

  • RicoWidmerRicoWidmer ✭✭ USMember ✭✭

    The app easily fills the screen on a small screen but leaves a lot of space on a big screen. Increasing the GUI on a big screen would use up the available space which looks better in my opinion. And a smaller GUI on a small screen doesn't look so squeezed.

Sign In or Register to comment.