Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolution-dependent font size in Xamarin

I am new with Xamarin and struggling with my first application. I have an image with an entry view above it. This way I create a custom entry background.

The font size of the entry won't scale with different devices with different resolutions though. When I adjust the font size for device A and now check the same app on device B the font size there is way too big.

I as well 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.

like image 916
telandor Avatar asked May 29 '15 10:05

telandor


1 Answers

I assume you are using Xamarin.Android rather than Xamarin Forms - you should not need to dyamically change the font size in code. Instead specify the fontSize in either a style or in the control itself and use 'sp' rather than px or dp (For example android:fontSize='16sp'.

Using 'sp' (scaled pixels) will scale appropriately depending on the user's device dpi (you can see a more indepth explaination here.

like image 183
codechinchilla Avatar answered Oct 15 '22 15:10

codechinchilla