Text is not aligned properly to vertically center in android textview

YogaPriyaYogaPriya Member ✭✭
edited January 18 in Xamarin.Android

In Xamarin.Android, I have used TextView with the LayoutParameter as WrapContent. But the text is not aligned to vertically center for the textView and additional space is always remains between the textview’s top and the text.

Code Example:
TextView textView = new TextView(this);
textView.SetBackgroundColor(Color.Yellow);
textView.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
textView.Text = "Rejected";
textView.SetTextColor(Color.Black);
textView.TextSize = 12;
textView.SetX(100);
textView.SetY(500);
SetContentView(textView);

Output:

Sample:

How to avoid the additional space at the top in text view or else how to align the text at vertically center when setting the LayoutParameters as WrapContent( I have tried by setting the Gravity as Center for TextView. But it does not work out in this case)

Sign In or Register to comment.