B4J Library [B4X][CustomView] xInstrumentationMeter

xInstrumentationMeter is an open source B4X library.
The xInstrumentationMeter (Custom View) purpose is to display meter value or to set a meter value via touch or mouse click.


  • Display a meter, horizontal or vertical, showing a value with a scale, bar and indicator.
  • Set the meter value (by code or touchable).
  • Many instrument properties can be set either in the visual designer or via methods (code).
  • Use as display only (readonly) by setting the custom view common property enabled to false.
  • Hint: Other usage possibilities, like meter as a progressbar.
The xInstrumentationMeter-NNN.zip (NNN is version number) archive contains
  • B4X library xInstrumentationMeter.b4xlib.
  • B4XPages sample project for B4A (tested with v11.0) & B4J (tested with v9.30).
  • NOTE: The B4i code is not developed further - The class v1.01 has been tested with B4i by @Johan Hormaza.
Copy the b4xlib file to the respective B4X additional libraries folder.

B4XPages Sample B4XMainPage.bas
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private xInstrumentationMeter1 As xInstrumentationMeter
    Private xInstrumentationMeter2 As xInstrumentationMeter
    Private xInstrumentationMeter3 As xInstrumentationMeter
    Private xInstrumentationMeter4 As xInstrumentationMeter
    Private btnSimulator As B4XView
    'Timer generating random level values for the indicators
    Private TimerLevel As Timer
End Sub

Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
    TimerLevel.Initialize("TimerLevel", 2000)
    TimerLevel.Enabled = False
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    B4XPages.SetTitle(Me, "B4X CV xInstrumentationMeter")
    CallSubDelayed(Me, "SetProperties")
End Sub

Private Sub SetProperties
    btnSimulator.Text = IIf(TimerLevel.Enabled, "Stop Simulator", "Start Simulator")
    'Just a few
    xInstrumentationMeter1.Value = 0
    xInstrumentationMeter2.Value = 100
    xInstrumentationMeter2.BarBackgroundColor = xui.Color_Green
End Sub

'Generate random indicator values
Sub TimerLevel_Tick
    xInstrumentationMeter1.Value = Rnd(xInstrumentationMeter1.ScaleMin, xInstrumentationMeter1.ScaleMax)
    xInstrumentationMeter2.Value = Rnd(xInstrumentationMeter2.ScaleMin, xInstrumentationMeter2.ScaleMax)
End Sub

Private Sub xInstrumentationMeter1_ValueChanged(value As Float)
    Log($"xInstrumentationMeter1_valueChanged: Value=${value}, Min=${xInstrumentationMeter1.ScaleMin}, Max=${xInstrumentationMeter1.ScaleMax}"$)
    xInstrumentationMeter1.Legend = $"${NumberFormat(value,0,xInstrumentationMeter2.ScaleDigits)}${xInstrumentationMeter2.Unit}"$
    xInstrumentationMeter3.Value =  xInstrumentationMeter2.Value
End Sub

Private Sub xInstrumentationMeter2_ValueChanged(Value As Float)
    Log($"xInstrumentationMeter2_valueChanged: Value=${Value}, Min=${xInstrumentationMeter2.ScaleMin}, Max=${xInstrumentationMeter2.ScaleMax}"$)
    xInstrumentationMeter2.Legend = $"Tank Level: ${NumberFormat(Value,0,xInstrumentationMeter2.ScaleDigits)}${xInstrumentationMeter2.Unit}"$
    xInstrumentationMeter4.Value =  xInstrumentationMeter1.Value
End Sub

Private Sub btnSimulator_Click
    TimerLevel.Enabled = Not(TimerLevel.Enabled)
    btnSimulator.Text = IIf(TimerLevel.Enabled, "Stop Simulator", "Start Simulator")
End Sub

GNU General Public License v3.0 - Developed for personal use only.

See file TODO.md.

Last Change
v1.20 (20211204) - Packed as B4XLib.
See file CHANGELOG.md.


  • xInstrumentationMeter-120.zip
    139.8 KB · Views: 72
Last edited:


Well-Known Member
Licensed User
Longtime User
Hi, I made some minor fixes to get it to work with B4i.
Here I attach the project in operation.
Great = Many thanks. Have updated post #1 attachment.

BTW: Working on a set of xInstrumentation CONTROLS --- so more to come :)
The next published is the xInstrumentationStateIndicator.
Here a preview of the StateIndicator which can also be touched to change the state. The number of Indicators can be set as a property.
Last edited:


Well-Known Member
Licensed User
Longtime User
Update v1.10 (20211116) - See Post #1
NEW: Property Bar background color.
NEW: Property Indicator Only - Do not show the bar, but only the indicator (ensure to size large).
NEW: Property Instrument panel background color, border width & color & corner radius.
NEW: Property Scale Font Color used for the scale and the value (if visible).
UPD: Minor changes.