C# 对齐文本视图';设置左、右、上、下值后的文本
我正在以编程方式设置C# 对齐文本视图';设置左、右、上、下值后的文本,c#,android,xamarin,xamarin.android,textview,C#,Android,Xamarin,Xamarin.android,Textview,我正在以编程方式设置文本视图的左、右、顶部、底部属性,该属性位于其同级的OnLayout方法中,它应该位于同级的顶部。但是,在我设置了这些属性之后,文本没有在中心对齐。它似乎是水平对齐,但不是垂直对齐 我已尝试设置TextView的Gravity以及TextAlignment的 protected override void OnLayout(bool changed, int left, int top, int right, int bottom) {
文本视图的左
、右
、顶部
、底部
属性,该属性位于其同级的OnLayout
方法中,它应该位于同级的顶部。但是,在我设置了这些属性之后,文本没有在中心对齐。它似乎是水平对齐,但不是垂直对齐
我已尝试设置TextView
的Gravity
以及TextAlignment
的
protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
{
_labelTextView = new TextView(Context)
{
Background = ContextCompat.GetDrawable(Context,
Resource.Drawable.blue_circle),
Text = "N/A",
Gravity = GravityFlags.Center,
TextAlignment = TextAlignment.Center,
};
_labelTextView.Left = left;
_labelTextView.Top = top + 20;
_labelTextView.Bottom = bottom - 50;
_labelTextView.Right = right;
base.OnLayout(changed, left, top, right, bottom);
}
需要的是\u labelTextView.Measure(0,0)调整边界后要调用的代码>
i、 e
需要的是\u labelTextView.Measure(0,0)调整边界后要调用的代码>
i、 e
_labelTextView.Left = left;
_labelTextView.Top = top + 20;
_labelTextView.Bottom = bottom - 50;
_labelTextView.Right = right;
_labelTextView.Measure(0, 0);