Xamarin.Android | ComponentOne
Controls / Gauge / Quick Start: Add and Configure / LinearGauge Quick Start
In This Topic
    LinearGauge Quick Start
    In This Topic

    This section describes how to add a C1LinearGauge control to your android application and set some of its properties.

    This topic comprises of two steps:

    The following image shows how the C1LinearGauge appears after completing the steps above:

    linear gauge with customized ranges

    Step 1: Add a C1LinearGauge control

    Complete the following steps to initialize a C1LinearGauge control in C#

    In Code

    1. Add the following reference in the MainActivity class file.
      C#
      Copy Code
      using C1.Android.Gauge;
    2. Instantiate the C1LinearGauge control in the MainActivity class file and set some of its properties as follows.
      C#
      Copy Code
      using Android.App;
      using Android.Widget;
      using Android.OS;
      using C1.Android.Gauge;
      
      namespace AndroidGauge
      {
          [Activity(Label = "AndroidGauge", MainLauncher = true)]
          public class MainActivity : Activity
          { 
          private C1LinearGauge mLinearGauge;
          private int mValue = 25;
          private int mMin = 0;
          private int mMax = 100;
              protected override void OnCreate(Bundle bundle)
              {
                  base.OnCreate(bundle);
                  mLinearGauge = (C1LinearGauge)FindViewById(Resource.Id.c1LinearGauge1);
                  mLinearGauge.Enabled = true;
                  mLinearGauge.Value = mValue;
                  mLinearGauge.Min = mMin;
                  mLinearGauge.Max = mMax;
                  mLinearGauge.Step = 1;
                  mLinearGauge.ShowText = GaugeShowText.All;
                  mLinearGauge.IsReadOnly = false;
                  mLinearGauge.IsAnimated = true;
                  // Set our view from the "main" layout resource
                  SetContentView(Resource.Layout.Main);
              }
          }
      }
    3. Add the following XML code in Main.axml in case of C#, to render the control onto the device.
      C#
      Copy Code
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:minWidth="25px"
          android:minHeight="25px">
          <C1.Android.Gauge.C1LinearGauge
              android:minWidth="25px"
              android:minHeight="25px"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/c1LinearGauge1" />
      </LinearLayoutradialGauge>

    Step 2: Run the Project

    In the ToolBar section, select the Android device and then press F5 to view the output.

    See Also