Xamarins Forms UWP App Images on scaled display - xamarin.forms

I have a laptop with a 4k display. The display properties are set to 3840 X 2160 (Recommended) for the resolution and the scale factor is set to 250% again, the recommended value. I have images in my project scaled with the following suffixes:
.scale-100.png
.scale-150.png
.scale-200.png
.scale-250.png
.scale-300.png
.scale-350.png
.scale-400.png
based on the documentation I found.
When I run the app, the images show up huge and throw the rest of the display off. Below is a screen shot:
if I set the scale to 100% - everything is tiny, but the images are correct. Here is a screen shot.
any idea how to fix this?

Derive from official document.
UWP image file names can be suffixed with .scale-xxx before the file extension, where xxx is the percentage of scaling applied to the asset, e.g. myimage.scale-200.png. Images can then be referred to in code or XAML without the scale modifier, e.g. just myimage.png. The platform will select the nearest appropriate asset scale based on the display's current DPI.
From your screen, it looks get the correct scale image, but your image control has been scale, Please try to set Aspect property as Fill for image control.
set the size on platform specific
OnPlatform is used to set specific value for each platform. For example
<StackLayout>
<StackLayout.Margin>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="0,20,0,0" />
<On Platform="Android, UWP" Value="0,0,0,0" />
</OnPlatform>
</StackLayout.Margin>
...
</StackLayout>
You could specific StackLayout margin for each platform like code above.

Related

Xamarin.Forms: Android picture renderer is basically useless

So, I am trying to achieve the effect as shown in this picture (regarding the party picture)
This is a snap shot from the iOS version of the app simply following this code:
<Image Source="{Binding picture}"/>
So, as you see, all thats needed to show this picture like this is one line of code (on iOS at least).
Cause this is what that will look like on Android:
So, youll see, it renderes it way too tiny, just inside a corner.
To get to (almost) the same results as on the iOS version, I have to alter the code like this:
<Image Source="{Binding picture}"
VerticalOptions="Start"
HorizontalOptions="StartAndExpand"
HeightRequest="171"/>
Giving it height values and so much more stuff, and in the end it still shows slight borders (about a pixel wide) and this is just a terrible solution.
What is the best way of showing the party image just the same as it is on the iOS version just on Android?
Why is Droid rendering the image tiner, not taking up all the space as iOS does?
There is an Aspect attribute inside Image. According to the official document, the default value of the Aspect attribute is AspectFit. You can auto-fill by setting the Aspect property to AspectFill. Here is the official document(https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.aspect?view=xamarin-forms)

Xamarin Forms: UI issue when running app on iPad

My app UIs are working fine on mobile screen devices. But when running on big screen devices like tablet the UI is not looking good. It is very difficult to read the text in tablet and icon sizes are also small. If I increase the icon size and font size for the tablet, it also affects small screen devices.
Screenshot:
See the above screenshot: On iPhone, it is very easy to read the text and view icons. But on the iPad, the text and icons are not in a good visible format.
My app is mainly for kids and so I need icons and text in a good readable form. So how can I solve this problem in all the devices?
Uploaded my XAML file on here.
It's very complicated to separate UI for iPhone and iPad in Xamarin.Forms . You could use the class Device .
The Device class contains a number of properties and methods to help developers customize layout and functionality on a per-platform basis.
In your case , you can use the Device.Idiom .
For example if you want to set different font size on iPad and iPhone
<Label.FontSize>
<OnIdiom x:TypeArguments="x:Double"
Phone="20"
Tablet="40"/>
</Label.FontSize>
You can set different value of property in xaml or code behind .For more details you can check https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/device#deviceidiom

ToolbarItem is showing a spot instead of image?

I'm creating an app using Xamarin and I am trying to add a ToolbarItem with icon, on Android it works fine but on iOS it just show a white spot as can see in the image below and I don't know why it is happening.
How could I fix this ?
ToolbarItem
<ContentPage.ToolbarItems>
<ToolbarItem Icon="icon.png" />
</ContentPage.ToolbarItems>
Toolbar on iOS by default is showing only the colored alpha of the image. If you want to use the colored image you need to specify that the rendering mode of your asset is not default, but rather original.

Xamarin forms: Image is not showing in perfect circle

I already posted a question regarding this issue, never get any solution. So posting the same question with more details and findings.
For the circle images, I am using Xam.Plugins.Forms.ImageCircle nuget package in my project, which is working fine in android and windows but showing an oval shape in IOS, screenshot adding below.
Added ImageCircleRenderer.Init(); in AppDelegate.cs.
xmlns namespace added:
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions"
<controls:CircleImage
HorizontalOptions="Start"
VerticalOptions="Start"
Margin="0,0,0,-5"
WidthRequest="50"
Aspect="AspectFill"
BorderColor="#1C7DB4"
BorderThickness="2"
HeightRequest="50" />
Now I updated the Xam.Plugins.Forms.ImageCircle to 2.0.2 and the resulted image is adding below:
Thanks in advance
It looks as if you are displaying the circles in a ListView, which has a fixed height of the cells per default. It seems as if your cells are simply not high enough to give the CircleImages the space they need. You have two options to overcome this:
Set the cells heigth to a fixed value that is high enough.
I don't know the exact value of the cells padding, so you'll have to experiment a bit. Maybe start off with something around 60
<ListView RowHeight="60" ...>
Set HasUnevenRows="true"
I believe that this will fix the rows height automagically, but it comes at costs: There may be a negative impact on layouting your view.
<ListView HasUnevenRows="true">

Meteor mobile-config.js launchScreens

I'm creating the splash images for my app but I've got some questions:
Can I create of all them at once? I've seen some repos for this but
there are not updated with new sizes (e.g 2048x1536)
Would be possible to use the same image for different sizes?
My phone is 1920x1080 but there is no splash screen size for that so it takes one and applies a disproportionate image. If I've got
text on it it looks really badly.
What happens with the rest of images when I build? Meteor removes the rest? Are located in resources/splash.
Could be possible to use a html with css page?
Thanks in advance!
Next time you should consider splitting your questions into independent posts.
Creating splash images: if your image is simple enough, indeed you have many scripts that can generate the different sizes automatically. I am sure you can customize them to fit your sizes.
Use the same image for different sizes: in general, that would mean your image will be stretched by the device to fill the screen. On Android, you can define a 9-patch PNG that will tell the device which pixels can be stretched, so that some part(s) of your image is not deformed.
Deformed image for 1920x1080 screen: depending on the pixel density, there should very probably be a placeholder for that.
Storage of image versions: by default, all versions (i.e. sizes) are packaged within your APK / APP, so that whatever the device needs will be available once user has downloaded the app.
Using an HTML+CSS page for splash screen: in general, no, but it depends on what you want to do with your splash screen. Meteor calls it "launch screen", because it is the first thing it displays while the app is loading / "launching". In particular, the WebView and local server may not be ready yet, and cannot serve any HTML/CSS. That is why you have to use a plain image, which is passed to a very simple activity while the app is loading. But some people also use a "waiting screen" between some parts of their app. In that case, your WebView and local server are already loaded, and you can simply use whatever you want.
Update:
For Android, if 9-patch PNG does not fit your need, you can also try to request Cordova's splashscreen plugin to maintain the aspect ratio of your image:
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-splashscreen/#preferences
<preference name="SplashMaintainAspectRatio" value="true" />
"SplashMaintainAspectRatio" preference is optional. If set to true, splash screen drawable is not stretched to fit screen, but instead simply "covers" the screen, like CSS "background-size:cover". This is very useful when splash screen images cannot be distorted in any way, for example when they contain scenery or text. This setting works best with images that have large margins (safe areas) that can be safely cropped on screens with different aspect ratios.
In Meteor, you would use App.setPreference in mobile-config.js:
App.setPreference("SplashMaintainAspectRatio", true, "android");

Resources