[mono-android] How to use "dip" or "dp" layout dimension for LayoutParams width and height?
Francesco Colombo
francesco.colombo at gmail.com
Thu Jun 28 13:45:58 UTC 2012
Hi,
i think you need a method like this
public static int AsPixels(float dp)
{
return
(int)Math.Round(YourActivityInstance.Resources.DisplayMetrics.Density * dp);
}
On Wed, Jun 27, 2012 at 9:18 PM, Sellec <echelonww at gmail.com> wrote:
> Sorry about my question, but i dont see any information in google.
> How can i set width like "30dp" for dynamically created label in my custom
> view?
> For example:
> var label1 = new TextView(this.Context);
> label1.LayoutParameters = new
> ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, 30);
> label1.Gravity = GravityFlags.CenterVertical;
> label1.SetText("test", TextView.BufferType.Normal);
> this.AddView(label1);
> But this height of 30 is set with normal pixels and looks different on
> emulator and real device (screen dimensions is different). And i dont see
> any way to set a type of pixels for layoutparams. How can i do this?
>
>
> --
> View this message in context:
> http://mono-for-android.1047100.n5.nabble.com/How-to-use-dip-or-dp-layout-dimension-for-LayoutParams-width-and-height-tp5710626.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodroid/attachments/20120628/375de411/attachment.html>
More information about the Monodroid
mailing list