manski

Get preferred list height in MonoDroid

Jul 4th, 2012
34
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private int GetPreferredListHeight() {
  2.   if (this.m_preferredListHeight == -1) {
  3.     TypedValue typedValue = new TypedValue(); //create a new typed value to received the resolved attribute value
  4.     DisplayMetrics displayMetrics = this.Context.Resources.DisplayMetrics;
  5.     int resId = Android.Resource.Attribute.ListPreferredItemHeight;
  6.     if (!this.Context.Theme.ResolveAttribute(resId, typedValue, true)) {
  7.       throw new ArgumentException("Resource ID #" + resId);
  8.     }
  9.  
  10.     if (typedValue.Type != DataType.Dimension) {
  11.       throw new ArgumentException("Resource ID #" + resId + " type " + typedValue.Type + " is not valid");
  12.     }
  13.  
  14.     this.m_preferredListHeight = TypedValue.ComplexToDimensionPixelSize(typedValue.Data, displayMetrics);
  15.   }
  16.  
  17.   return this.m_preferredListHeight;
  18. }
RAW Paste Data