Search code examples
androidxamarin.androidteechart

Teechart is displaying compressed on first load because expanded keyboard shrinks the view


I have an FragmentActivity that uses the ActionBar Tabs, one of the tabs has a tab host that holds a series of charts.

This activity is start by a search so the keyboard is disappearing as the activity is loading, this causes the chart of the first tab to display compressed. This only happens on the first load of the activity. On my second search the chart displays in full.

the The TabHost activity looks like this,

[Activity]
public class MonthlySalesChartView : Activity
{
    private CustomerRepository _customerRespository;
    private BaseChart _chart;
    private string _code;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        _customerRespository = new CustomerRepository();

        _chart = BuildChart();

        _code = Intent.GetStringExtra("customer_code");

        SetContentView(_chart);
    }

    private BaseChart BuildChart()
    {
        var data = _customerRespository.GetMonthlySalesData(_code);
        var tChart = new BaseChart(ApplicationContext, "Monthly Sales History");
        tChart.Axes.Left.Title.Text = "Spend ($)";
        tChart.Aspect.View3D = false;
        var bar1 = new BaseBar(tChart.Chart) { Title = "Customer Spend" };
        bar1.Marks.Visible = false;
        var avgLine = new Line(tChart.Chart) { Title = "Average Spend", Dark3D = false, LinePen = { Width = 4 } };

        foreach (var month in data.ResultSet.MonthlySales)
        {
            bar1.Add(month.Value, month.MonthName);
        }

        avgLine.DataSource = bar1;
        avgLine.Function = new Average(true);
        avgLine.Depth = 50;

        return tChart;
    }
}

An example of what is looks like

Chart


Solution

  • Try adjusting

    set the input mode in your AndroidManifest.xml on the activity.

    android:windowSoftInputMode="stateVisible|adjustPan"
    

    This adjusts how the system handles adjusting the screen to accomodate for the keyboard taking up screen real estate.