2017-11-23 6 views
1

I 프로그래밍 방식의 OnLayout 방법에 TextViewLeft, Right, Top, Bottom 속성을 설정하면이 위에 앉아 해야하는 형제의입니다. 그러나 텍스트는 이 아니며 해당 속성을 설정 한 후이 가운데 정렬됩니다. 가로로 정렬되지만 세로로 정렬하지 않는 것 같습니다.정렬 텍스트 뷰의 텍스트 왼쪽, 오른쪽, 위쪽을 설정 한 후, 하단 값

나는 GravityTextView뿐만 아니라 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); 
     } 

답변

0

_labelTextView.Measure(0, 0);을했다가 경계를 조정 한 후 호출 할 수 있습니다.

_labelTextView.Left = left; 
_labelTextView.Top = top + 20; 
_labelTextView.Bottom = bottom - 50; 
_labelTextView.Right = right; 

_labelTextView.Measure(0, 0);