Hi Erel,
I tried what you suggested using two image views and it worked great. I then tried to turn it into a class so I could use it over and over, but I couldn't get this to work.
My main program is:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 450
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private compass1 As compassView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("main") 'Load the layout file.
MainForm.Show
compass1.Angle = 33
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub compass1_MouseClicked (EventData As MouseEvent)
End Sub
My class is:
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Public mBase As B4XView
Private xui As XUI 'ignore
Private iVcompScale As B4XView
Private iVpointer As B4XView
Public Tag As Object
End Sub
Sub globals
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
End Sub
'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
mBase = Base
Tag = mBase.Tag
mBase.Tag = Me
' Dim clr As Int = xui.PaintOrColorToColor(Props.Get("TextColor")) 'Example of getting a color value from Props
Sleep(0)
mBase.LoadLayout("compass_cv")
End Sub
public Sub setAngle(angleDeg As Double)
iVpointer.Rotation = angleDeg
End Sub
public Sub setReciprocalAngle(angleDeg As Double)
If angleDeg >= 180 Then
iVpointer.Rotation = angleDeg - 180
Else
iVpointer.Rotation = angleDeg + 180
End If
End Sub
Private Sub Base_Resize (Width As Double, Height As Double)
End Sub
I have two layouts a main which has the compassView view and a second view called compass_cv which has two images one for the scale and one for the pointer.
The problem occurs when the iVpointer.Rotation function is executed. Of course iVpointer hasn't been set so its Null and the program crashes.
Trouble is I can't figure out out how to set the iVpointer variable and keep it set. I tried setting it using the following piece of code in the initialisation function of the class:
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(100, 0, 0, 600dip, 600dip)
p.LoadLayout("compass_cv")
Log(p.NumberOfViews) 'There were 2 which is correct'
iVpointer = p.GetView(0).Tag
End sub
Sadly this didn't work either because the class variables aren't persistent and get reset to null before the setAngle function is called.
I searched high and low for a solution or example, but I didn't do any good.
What must I do to get it to work?
Best regards
Rob