Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Size of Screen in a Custom Renderer

$
0
0

Hello,

I might ask a pretty easy question but I have been trying to get the size of the Screen in a custom renderer to change the size of a Button accordingly. I might be doing something wrong, but then again, I am a bit lost since everytime I try to get the Width and the Height of a Context, I get -1.

Here is the code I am using for android renderer :

public class FBButtonRenderer : ButtonRenderer
{

    int i;
    Typeface myType;
    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
    {
        base.OnElementChanged(e);
        var button = e.NewElement; // Xamarin.Forms.Button control
        i = Width;                       <----------- My problem lies here

        if (this.Control != null)
        {
            Drawable img = this.Context.Resources.GetDrawable(Resource.Drawable.facebooklogomini);
            myType = Typeface.CreateFromAsset(this.Context.Assets, "Raleway-Thin.ttf");
            Control.SetTypeface(myType, TypefaceStyle.Normal);
            Control.SetBackgroundColor(Android.Graphics.Color.ParseColor("#3c5a99"));
            Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(img, null, null, null);

        }
    }
}

I have been searching the web for an answer, but since I can't find one, maybe it is the wrong procedure. I have been vaguely thinking about using an interface to get the Width and Height of the screen but I am not sure if it is the right way.

Anyhow, I am leaving this question in your care. Thank you for your patronage.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>