Bug 12519 - Beta: Properties DisplayMetrics.Density, DisplayMetrics.ScaledDensity are 0
Summary: Beta: Properties DisplayMetrics.Density, DisplayMetrics.ScaledDensity are 0
Status: RESOLVED DUPLICATE of bug 12007
Alias: None
Product: Android
Classification: Xamarin
Component: Pre-release ()
Version: 4.7.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2013-06-03 08:43 UTC by maksimko
Modified: 2013-06-04 11:18 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 12007

Description maksimko 2013-06-03 08:43:30 UTC
Beta channel

API: 10 - 12

var metrics = Application.Context.Resources.DisplayMetrics;
var scaledDensity = metrics.ScaledDensity;
var density = metrics.Density;

Both ScaledDensity and Density are 0.
Comment 1 Jonathan Pryor 2013-06-03 17:07:10 UTC
What do you mean by "API: 10-12"?

Do you mean when running on a device using Android v2.3.3-v3.1? When the $(TargetFrameworkVersion) is targeting Android v2.3.3-v3.1? Something else?

Does this happen in 4.6.x?
Comment 2 maksimko 2013-06-03 18:19:34 UTC
Yes, i run predefined Android v2.3.3(and 3.1) emulator with ARM (armeabi) CPU/ABI setting.

Sorry, the problem was not in DisplayMetrics properties. 
I make some tests - all float properties returns 0 instead of actual value.

Code bellow shows "Get Prop1: 0" in predefined 2.3.3/3.1 emulators with armeabi.
But with Intel and in stable channel it works correct.

namespace TestApp {
	[Activity (Label = "TestApp", MainLauncher = true)]
	public class Activity1 : Activity {

		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			var testClass = new TestClass ();
			float prop1 = testClass.Prop1;

			Console.WriteLine ("Get Prop1: {0}", prop1);
		}
	}

	public class TestClass {
		public float Prop1 { get { return 0.5f; } }
	}
}
Comment 3 Jonathan Pryor 2013-06-03 21:34:50 UTC
This sounds like Bug #12007, which was fixed in 4.7.5. Which Xamarin.Android version are you using?
Comment 4 maksimko 2013-06-04 01:17:56 UTC
Guess you are right.

I use Xamarin.Android Version: 4.7.4.
Comment 5 Jonathan Pryor 2013-06-04 11:18:27 UTC
Please try on 4.7.5 or later. :-)

*** This bug has been marked as a duplicate of bug 12007 ***