2017-11-23 9 views
1

を設定した後、私は、プログラムでのOnLayout方法でTextViewLeftRightTopBottom性質は、の上に座ることになっています兄弟だ設定しています。しかし、テキストはで、ではなく、これらのプロパティを設定した後で中心に揃っています。それは水平に整列しているように見えますが、垂直に整列していないようです合わせのTextViewのテキストは左、右、上、下の値

私はTextViewGravityなど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); 
関連する問題