Adding TextView in Picker via PickerRenderer

DiamondKesha 31 Reputation points
2020-11-30T17:12:41.773+00:00

Hello everyone.
After adding TextView to the Picker via the PickerRenderer, the text of the selected item is shifted to the right. How i can fix this?

Image of the Picker (where the red lines are indents that should not be):
43650-image.png

Code:

        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)  
        {  
            base.OnElementChanged(e);  
              
            var textV = new TextView(this.Context);  
  
            textV.Text = "Title";  
            textV.TextSize = 14;  
            textV.SetTextColor(Android.Graphics.Color.Black);  
  
            Control.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(textV), null, null, null);  
        }  
  
        private BitmapDrawable GetDrawable(TextView textV)  
        {  
              
            var bitmap = Bitmap.CreateBitmap(100, 100, Bitmap.Config.Argb8888);  
            var canvas = new Canvas(bitmap);  
  
            textV.Layout(0, 0, 80, 100);  
            textV.Draw(canvas);  
  
            var bitmapDrawable = new BitmapDrawable(Context.Resources, bitmap);  
            return bitmapDrawable;  
        }  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,284 questions
{count} votes