HeaderTextAlignment problem when using different BackgroundColors

Hi,

I have a grid with several Columns and each HeaderColumn has a different color using code:

            GridTextColumn column2 = new GridTextColumn();
            column2.MappingName = "RentingCosts";
            column2.LineBreakMode = LineBreakMode.NoWrap;
            column2.LoadUIView = true;
            column2.HeaderTextMargin = 0;
            var tvRentingCosts = new TextView(v.Context);
            tvRentingCosts.Text = "Renting Costs";
            tvRentingCosts.SetBackgroundColor(Color.Red);
            tvRentingCosts.SetTypeface(null, TypefaceStyle.Bold);
            tvRentingCosts.SetTextColor(Color.Black);
            tvRentingCosts.SetTextSize(Android.Util.ComplexUnitType.Dip, 11);
            column2.HeaderTemplate = tvRentingCosts;
            dataGrid.Columns.Add(column2);

This works well but the text of tvRentingCosts in column2 is positioned in the left upper corner while I want it to be centered Horizontal and Vertical.

I tried setting the HeaderTextAlignment of column2 and the TextAlignment of tvRentingCosts but nothing changes. Do you have a solution?



3 Replies

SK Shivagurunathan Kamalakannan Syncfusion Team February 1, 2018 06:24 PM UTC

Hi Vince, 
 
We have checked your query. Your requirement to set the HeaderText’s TextAlignment to the center can be achieved by using GravityFlags. 
 
Refer the below KB for more details. 
 
Refer the below code for more details. 
 
 
public class MainActivity : Activity 
{ 
    private SfDataGrid dataGrid; 
 
    private TextView orderIDTextView; 
    private TextView customerIDTextView; 
    private TextView shipCountryTextView; 
    private TextView customerTextView; 
    private TextView shipCityTextView; 
 
 
    protected override void OnCreate(Bundle bundle) 
    { 
       
        dataGrid = new SfDataGrid(this); 
        orderIDTextView = new TextView(this); 
        customerIDTextView = new TextView(this); 
        shipCountryTextView = new TextView(this); 
        customerTextView = new TextView(this); 
        shipCityTextView = new TextView(this); 
        base.OnCreate(bundle); 
 
        // Set our view from the "main" layout resource 
        SetContentView (Resource.Layout.Main); 
        OrderInfoRepository viewModel = new OrderInfoRepository(); 
        dataGrid.ItemsSource = viewModel.OrderInfoCollection; 
 
        dataGrid.AutoGenerateColumns = false; 
        dataGrid.ColumnSizer = ColumnSizer.Star; 
 
        orderIDTextView.Text = "Order ID"; 
        orderIDTextView.Gravity = Android.Views.GravityFlags.Center; 
        orderIDTextView.SetBackgroundColor(Color.SandyBrown); 
        orderIDTextView.SetTextColor(Color.Black); 
 
 
 
        GridTextColumn OrderIDColumn = new GridTextColumn(); 
        OrderIDColumn.MappingName = "OrderID"; 
        OrderIDColumn.HeaderTemplate =orderIDTextView; 
        OrderIDColumn.LoadUIView = true; 
 
 
        dataGrid.Columns.Add(CustomerIDColumn); 
        dataGrid.Columns.Add(OrderIDColumn); 
        dataGrid.Columns.Add(ShipCountryColumn); 
        dataGrid.Columns.Add(CustomerColumn); 
        dataGrid.Columns.Add(ShipCityColumn); 
         
         
        LinearLayout linear = FindViewById<LinearLayout>(Resource.Id.linear); 
        linear.AddView(dataGrid); 
    } 
} 
 
 
 
We have prepared a sample based on your requirement and you can download the same from below Link. 
 
 
Regards, 
Shivagurunathan. K 



VI Vince February 2, 2018 08:34 AM UTC

Hi Shivagurunathan,

Thanks for your reply.

I added the code "tvRentingCosts.Gravity = GravityFlags.Center;" in my app and now the text in the header column is centered horizontal but it is not centered vertical. So it remains at the top of the header column while I want it to be centered vertical.

How can I achieve that?


SK Shivagurunathan Kamalakannan Syncfusion Team February 5, 2018 08:39 PM UTC

Hi Vince

Thank you for using Syncfusion products. We confirmed that the issue with “Text alignment for column header does not get centralized vertically” is a defect and we have logged a defect report. The fix for this issue is estimated to be available on any of our upcoming releases. We appreciate your patience until then.

Regards,
Shivagurunathan Kamalakannan
 


Loader.
Up arrow icon