chrfalch / NControl

Simple Xamarin.Forms wrapper control around the NGraphics library
MIT License
267 stars 67 forks source link

Android Pixel Issue #58

Open JoshuaNovak919 opened 8 years ago

JoshuaNovak919 commented 8 years ago

NControl uses pixels on Android, which is fine, but if you setup a control that has parameters like corner radius or anything size related, the size will be different on devices with different densities since the pixels change, but your parameter doesn't. Is there a good way to convert the size without having to use XLabs' IDevice or another library?

durandt commented 8 years ago

Hi,

I develop a Xamarin.Forms application that targets both iOS and Android and I was surprised to realize that NControl consider the given coordinates as points on iOS (scale-independent)(called density pixels on Android) but uses pixels on Android.

The downside is that it forces us to add code than handle Android specifically, which is exactly what we are trying to avoid using NControl.

So I join my voice to @JoshuaNovak919 's and ask if this is by design, or a bug, and if there's any plan to change that in the future.

Regards,

BlueRaja commented 5 years ago

This bug makes NControl basically unusable in Android. No drawing code works correctly across devices of different densities. Does anyone actually use this control!?

I've found the solution to be adding a Density property to NViewControl, then setting it to Forms.Context.Resources.DisplayMetrics.Density in NControlViewRenderer.OnElementChanged, then multiplying all coordinates by Density before calling any Draw() functions. This fixes drawing in Android, but obviously means you have to compile from an edited version of the source (Ahh!). It's also a huge pain in the ass that shouldn't be necessary.

I'm going to try rewriting my control using SkiaSharp.Views.Forms, this is ridiculous.

jocontacter commented 5 years ago

This bug makes NControl basically unusable in Android. No drawing code works correctly across devices of different densities. Does anyone actually use this control!?

until it not fixed try to use CrossCurrentActivity plugin: CrossCurrentActivity.Current.Activity.Resources.DisplayMetrics.Density
or use XLabs.IDevice for android and multiplicate your sizes by this value.