Forum Xamarin.Forms

Xamarin forms use native platform specific controls.

YogeshPatil.2761YogeshPatil.2761 USMember ✭✭
edited April 2016 in Xamarin.Forms

In my Xamarin forms App I want to show platform specific controls Spinner in Android and Segmented Control in iOS. I have written the custom view(Derived from Xamarin Forms View) and platform specific renderers(ViewRenderer). For Android in "OnElementChanged" method I am setting Spinner view. But it ends in following exception:

Java.Lang.RuntimeException: Binary XML file line #19: You must supply a layout_height attribute.

I tried to set LayoutParams but it's not working.

StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="Center" BackgroundColor="Aqua"
local:CustomGradeView HorizontalOptions="Fill" VerticalOptions="Fill"

public class CustomGradeView : View{}

public class CustomGradeRenderer : ViewRenderer
        Spinner spinnerView;

        protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.View> e)
            base.OnElementChanged (e);

            // SetNativeControl (new TextView(Context){Text="Test for renderer"}); Working fine, no issues.

            spinnerView = new Spinner (Context);
            spinnerView.LayoutParameters = new LayoutParams (100, 100);             
            ArrayAdapter<string> spinnerAdapter = 
                new ArrayAdapter<string> (Context, Resource.Layout.support_simple_spinner_dropdown_item, grades);
            spinnerView.Adapter = spinnerAdapter;
            SetNativeControl (spinnerView); // Exception


  • GroegGroeg ATMember ✭✭

    I'd love to know as well (though I get the exception at GetDesiredSize)

Sign In or Register to comment.