I can take a look at it, but currently I'm working on 3 existing views where I'm developing updates that need to be completed first.Anyone can help me ?
I would like to donate for such a view for b4x.I can take a look at it, but currently I'm working on 3 existing views where I'm developing updates that need to be completed first.
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private CustomListView1 As CustomListView
Private currentIndex As Int
Private touchPanel As Panel
Private startPointX As Float
Private panelWidth As Float
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
panelWidth = Root.Width / 3
Sleep(10)
Dim touchPanel As Panel
touchPanel.Initialize("touchpnl")
Root.AddView(touchPanel, 0, 0, Root.Width, Root.Height)
For i = 0 To 5
Dim pnl As B4XView = xui.CreatePanel("")
pnl.SetColorAndBorder(xui.Color_White, 2dip, xui.Color_Black, 0)
pnl.SetLayoutAnimated(0, 0, 0, (Root.width - 50) / 3, Root.Height)
Log(Root.Width / 3)
Dim lbl As Label: lbl.Initialize("")
Dim lblx As B4XView = lbl
lblx.SetTextAlignment("CENTER", "CENTER")
lblx.SetColorAndBorder(xui.Color_RGb(220, 220, 255), 1dip, xui.color_black, 0)
If i = 0 Or i = 5 Then
lblx.Text = "Blank"
Else
lblx.Text = "XXXX " & i
End If
pnl.AddView(lblx, 30dip, 30dip, pnl.Width - 60dip, pnl.Height - 60dip)
CustomListView1.Add(pnl, i)
Next
currentIndex = 1
Dim pnl As B4XView = CustomListView1.GetPanel(currentIndex)
Dim lblx As B4XView = pnl.GetView(0)
lblx.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.height)
End Sub
Sub touchpnl_Touch(Action As Int, X As Float, Y As Float)
Dim saveIndex As Int = currentIndex
Select Action
Case touchPanel.ACTION_DOWN
startPointX = X
Case touchPanel.ACTION_MOVE
Case touchPanel.ACTION_UP
Dim pnl As B4XView = CustomListView1.GetPanel(saveIndex)
Dim lblx As B4XView = pnl.GetView(0)
lblx.SetLayoutAnimated(0, 30dip, 30dip, pnl.Width - 60dip, pnl.Height - 60dip)
If X > startPointX Then
If currentIndex > 1 Then animateToRight Else currentIndex = currentIndex + 1
currentIndex = currentIndex - 1
Else If X < startPointX Then
currentIndex = currentIndex + 1
If currentIndex < CustomListView1.size - 1 Then animateToLeft Else currentIndex = currentIndex - 1
End If
Dim pnl As B4XView = CustomListView1.GetPanel(currentIndex)
Dim lblx As B4XView = pnl.GetView(0)
lblx.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.height)
End Select
Sleep(10)
End Sub
private Sub animateToLeft
Dim startOffset As Int = CustomListView1.sv.ScrollViewOffsetX
Dim targetOffset As Int = startOffset + panelWidth
Dim stepSize As Float = (targetOffset - startOffset) / 10
Do While startOffset < targetOffset
startOffset = startOffset + stepSize
If startOffset > targetOffset Then Exit
CustomListView1.sv.ScrollViewOffsetX = startOffset
Sleep(10)
stepSize = Max(5, stepSize - 1)
Loop
CustomListView1.sv.ScrollViewOffsetX = targetOffset
End Sub
private Sub animateToRight
Dim startOffset As Int = CustomListView1.sv.ScrollViewOffsetX
Dim targetOffset As Int = startOffset - panelWidth
Dim stepSize As Float = (targetOffset - startOffset) / 10
Do While startOffset > targetOffset
startOffset = startOffset + stepSize
If startOffset < targetOffset Then Exit
CustomListView1.sv.ScrollViewOffsetX = startOffset
Sleep(10)
stepSize = Min(-5, stepSize - 1)
Loop
CustomListView1.sv.ScrollViewOffsetX = targetOffset
End Sub
Thank you. I will tryB4XPages.. Here is a start, I put it in landscape, but you will see how to modify it for your needs. So far 100 lines.
You'll need a CustomListView in MainPage (anchored at all edges).
(I just started a photography hobby and this would be useful.)
B4X:#Region Shared Files #CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files" 'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True #End Region 'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip Sub Class_Globals Private Root As B4XView Private xui As XUI Private CustomListView1 As CustomListView Private currentIndex As Int Private touchPanel As Panel Private startPointX As Float Private panelWidth As Float End Sub Public Sub Initialize End Sub Private Sub B4XPage_Created (Root1 As B4XView) Root = Root1 Root.LoadLayout("MainPage") panelWidth = Root.Width / 3 Sleep(10) Dim touchPanel As Panel touchPanel.Initialize("touchpnl") Root.AddView(touchPanel, 0, 0, Root.Width, Root.Height) For i = 0 To 5 Dim pnl As B4XView = xui.CreatePanel("") pnl.SetColorAndBorder(xui.Color_White, 2dip, xui.Color_Black, 0) pnl.SetLayoutAnimated(0, 0, 0, (Root.width - 50) / 3, Root.Height) Log(Root.Width / 3) Dim lbl As Label: lbl.Initialize("") Dim lblx As B4XView = lbl lblx.SetTextAlignment("CENTER", "CENTER") lblx.SetColorAndBorder(xui.Color_RGb(220, 220, 255), 1dip, xui.color_black, 0) If i = 0 Or i = 5 Then lblx.Text = "Blank" Else lblx.Text = "XXXX " & i End If pnl.AddView(lblx, 30dip, 30dip, pnl.Width - 60dip, pnl.Height - 60dip) CustomListView1.Add(pnl, i) Next currentIndex = 1 Dim pnl As B4XView = CustomListView1.GetPanel(currentIndex) Dim lblx As B4XView = pnl.GetView(0) lblx.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.height) End Sub Sub touchpnl_Touch(Action As Int, X As Float, Y As Float) Dim saveIndex As Int = currentIndex Select Action Case touchPanel.ACTION_DOWN startPointX = X Case touchPanel.ACTION_MOVE Case touchPanel.ACTION_UP Dim pnl As B4XView = CustomListView1.GetPanel(saveIndex) Dim lblx As B4XView = pnl.GetView(0) lblx.SetLayoutAnimated(0, 30dip, 30dip, pnl.Width - 60dip, pnl.Height - 60dip) If X > startPointX Then If currentIndex > 1 Then animateToRight Else currentIndex = currentIndex + 1 currentIndex = currentIndex - 1 Else If X < startPointX Then currentIndex = currentIndex + 1 If currentIndex < CustomListView1.size - 1 Then animateToLeft Else currentIndex = currentIndex - 1 End If Dim pnl As B4XView = CustomListView1.GetPanel(currentIndex) Dim lblx As B4XView = pnl.GetView(0) lblx.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.height) End Select Sleep(10) End Sub private Sub animateToLeft Dim startOffset As Int = CustomListView1.sv.ScrollViewOffsetX Dim targetOffset As Int = startOffset + panelWidth Dim stepSize As Float = (targetOffset - startOffset) / 10 Do While startOffset < targetOffset startOffset = startOffset + stepSize If startOffset > targetOffset Then Exit CustomListView1.sv.ScrollViewOffsetX = startOffset Sleep(10) stepSize = Max(5, stepSize - 1) Loop CustomListView1.sv.ScrollViewOffsetX = targetOffset End Sub private Sub animateToRight Dim startOffset As Int = CustomListView1.sv.ScrollViewOffsetX Dim targetOffset As Int = startOffset - panelWidth Dim stepSize As Float = (targetOffset - startOffset) / 10 Do While startOffset > targetOffset startOffset = startOffset + stepSize If startOffset < targetOffset Then Exit CustomListView1.sv.ScrollViewOffsetX = startOffset Sleep(10) stepSize = Min(-5, stepSize - 1) Loop CustomListView1.sv.ScrollViewOffsetX = targetOffset End Sub
View attachment 139835
Sub touchpnl_Touch(Action As Int, X As Float, Y As Float)
Dim threshold As Float = frameWidth / 5 'or even smaller
Select Action
Case touchPanel.ACTION_DOWN
startPointX = X
Case touchPanel.ACTION_MOVE
Case touchPanel.ACTION_UP
If X > (startPointX + threshold) Then
currentIndex = currentIndex - 1
If currentIndex > 1 Then animateToRight Else currentIndex = currentIndex + 1
Else If X < (startPointX - threshold) Then
currentIndex = currentIndex + 1
If currentIndex < CustomListView1.size - 2 Then animateToLeft Else currentIndex = currentIndex - 1
Else
'a click - use X to determine where on the screen
'X could be right third of screen or center third or left third
End If
End Select
Sleep(10)
End Sub
Let me explain.If you mean click on the left or right instead of a swipe, then..
You have to differentiate a swipe from a click.
Simply put a threshold on the swipe distance below which it is a click.
B4X:Sub touchpnl_Touch(Action As Int, X As Float, Y As Float) Dim threshold As Float = frameWidth / 5 'or even smaller Select Action Case touchPanel.ACTION_DOWN startPointX = X Case touchPanel.ACTION_MOVE Case touchPanel.ACTION_UP If X > (startPointX + threshold) Then currentIndex = currentIndex - 1 If currentIndex > 1 Then animateToRight Else currentIndex = currentIndex + 1 Else If X < (startPointX - threshold) Then currentIndex = currentIndex + 1 If currentIndex < CustomListView1.size - 2 Then animateToLeft Else currentIndex = currentIndex - 1 Else 'a click - use X to determine where on the screen 'X could be right third of screen or center third or left third End If End Select Sleep(10) End Sub
If you you have other questions, please mark this as solved and start a new thread.