How to scale fontsize on different devices programmatically (Xamarin.android)? - xamarin.android

I'm new to Xamarin and I'm actually developing an Android App. I've tried to run the app on different Android phones, but the fontSize appears either too small or large. Programmatically, how can I scale the FontSize of texts so that it can be adjust according to the device's screen?

Firstly, make sure you are using sizes in dp not px (or in, mm etc.) as these will factor in the screen density.
If you still have an issue, look at Screens support in the Android Docs, especially Using configuration qualifiers. Examples can be found here.
Basically you would need to provide a different resource file for each screen size. You should have a file something like res/values/dimens.xml where you store sizes for all your components. Make sure your font sizes are declared and referenced from here. You can then create a series of folders/files for the different screen sizes
res/values/dimens.xml
res/values-sw320dp/dimens.xml
res/values-sw720dp/dimens.xml
res/values-sw1024dp/dimens.xml
where each of these folders define the smallest width screen that that file will be used for.

Related

Which size of fxml gui is right?

I have problems with gluon-mobile view sizing FXML, it use a different size I'm confused.
in the sample gluon-mobile it uses 350 x Height 600.
But in the scene builder File-> new Template it creates with 335 x Height 600
both Template.
I need it for setup my Adobe XD for design the background image.
Can it be specified?
Those sizes (350x600, 335x600) are set for reference, and to test on desktop, based on usual mobile formats, but the real size will be defined by the real device, and this can vary.
See for instance https://material.io/tools/devices/, where you can find several devices with 360x640 dp, but many other resolutions as well.
When you display your view with Gluon Mobile on a real device, the scene will take the full available size.
If you want to retrieve this value, you can use the DisplayService (see doc):
Services.get(DisplayService.class).ifPresent(service -> {
// screen resolution of the device, in pixels
Dimension2D resolution = service.getScreenResolution();
System.out.printf("Screen resolution: %.0fx%.0f", resolution.getWidth(), resolution.getHeight());
// default screen dimensions of a mobile device, in dp
Dimension2D dimensions = service.getDefaultDimensions();
System.out.printf("Screen dimensions: %.0fx%.0f", dimensions.getWidth(), dimensions.getHeight());
});
If you want to use an image for the background, you can use css to set it to expand or adjust properly to the final size, as documented here for -fx-background-image.
ok, it's mean that I need export design img in all sizes like to
mipmap-hdpi
mipmap-ldpi
...
mipmap-xxxhdpi
?

Understanding default font sizes in React Native

I've been working on a React Native app for the past few months, and something has always eluded me that I'm just now trying to get to the bottom of. I'm trying to standardize the font sizes within my app (for body, headers, etc.) and am struggling to understand where exactly React Native gets its default font size from. I've been testing in an iPhone 8 simulator running iOS 11, and through experimentation have come to the conclusion the default font displayed is 14 logical pixels (as in a brand-new element with no styling). However, checking the iOS style guidelines it would seem the default body text on iOS is intended to be 17pt. Although I don't a ton about device scaling, I've tried crunching the numbers in every online converter I could find, and could not come up with how 17pt may come close to 14 logical pixels (assuming RN uses the body font size by default). The only way I was able to roughly translate the two was if the DPI was around 90, but the DPI for iPhones is much, much higher. So might anyone be able to offer insight as to how default fonts are selected in React Native? Even hunting through the source code I couldn't find much. I'd like to be able to calculate the base size myself so I can scale the other font sizes according. Thanks in advance!
I suggest you to look at react-native-element's helper method normalizeText. It calculates the pixel ratio and set the texts fontSize accordingly.
Also you should also take in consideration of Accessibility Text Size Option in iOS. This option will be affecting all your app.

Application icons is pixelated

I'm trying to set an icon for my app, however the icons derived from the original image are pixelated and look bad. I tried to provide the app icon gear application with images of different sizes, however the result is still unpleasant.
Should I provide it with images of higher resolution or lower resolution to get better results?
The answer to this question links to to a matrix provided by Apple for icon sizes. Should I use these sizes strictly, consider them as a lower border not to go under, or consider them as a ceiling not to exceed?
The docs states
Table 45-1 lists the sizes required for these custom icons and images.
Use the exact sizes.

Adapting iOS UI to work for tvOS

We have an iOS app and we were asked to also support tvOS. All our UI is done in .xib files, but the problem is that all the sizes for views, margins, text, etc. are in points. That was totally fine for the iPhones and iPads, as the points are pixels multiplied by a scale to get them to look the same on all resolutions.
But when we built the app for tvOS, all our views are small and in the center of the pages. I read that this is caused because the resolution for tvOS is 1080p, with a scale of 1x. See article here.
For the UI to look the same, I would like to multiply everything by a scale of 4. By everything, I mean again: view size, text size, margins, spacing, etc.
Is there a way of doing such a thing without completely rewiring the UI?

What size image should I use for BlackBerry context menus?

The BB OS 5.0 supports images for context menus. The API documentation says the image will be scaled to fit a square set by the height of the menu font. I find that totally unhelpful.
The only way I can explain that method of calculation is due to screen resolution and DPI. But since the 5.0 OS is only valid on a handful of devices with similar screen sizes, I reckon they can specify the actual icon size they use.
I'd like to choose an icon size that's closest to the default menu font height so that the they look OK.
What size do you use? Do you even use this feature?
I haven't used it yet, but I would recommend using any square ratio maybe up to 64x64; the problem is that with new devices on the horizon (eg rumored tablet - with much bigger display) it won't necessarily be practical to target a specific screen size.

Resources