Android Question About HorizontalScrollView touch event

Jones Hone

Active Member
Licensed User
Longtime User
There are some buttons on the HorizontalScrollView,
When scroll button can't trigger ACTION_DOWN event, only scroll HorizontalScrollView can triger.
How can I scroll the button to trigger the ACTION_DOWN event?
Thank you very much.
Below is my code:
B4X:
Sub Process_Globals
    Public hsvTimer As Timer
End Sub

Sub Globals
    Private Pn As Int = 10
    Private hsview As HorizontalScrollView
    Private R As Reflector
    Private button(Pn*3) As Button
    Private NowPage As Int=0
    Private memX As Int
    Dim pnl As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    hsview.Initialize(100%x,"hsview")
    hsview.Color = Colors.Cyan
    Activity.AddView(hsview,0,0dip,100%x,120dip)
    pnl=hsview.Panel
    pnl.Width = hsview.Width * Pn
  
    hsvTimer.Initialize("hsvTimer",100)
  
    R.Target = hsview
    R.SetOnTouchListener("hsview_Touch")

    Dim i As Int,n As Int=0,w As Int
    w=(100%x-20)/3
    For i = 0 To Pn*3-1
        button(i).Initialize("button")
        button(i).Text = "Button" & i
        button(i).Color = Colors.LightGray
        button(i).Textcolor=Colors.Black
        pnl.AddView(button(i),(n*100%x)+(i Mod 3)*w, 0, w, 60dip)
        If (i+1) Mod 3 = 0 Then
            n=n+1
        End If
    Next
End Sub

Private Sub hsview_Touch(ViewTag As Object, Action As Int, X As Float, y As Float, MotionEvent As Object) As Boolean
    Select Action
        Case 0    ' ACTION_DOWN
            memX = X
            Log("Dn:" & Round(X) )
        Case 1    ' ACTION_UP
            Log("Up:" & Round(x) )
            If memX > x  Then
                Log("==>" )
                NowPage=NowPage+1
                If NowPage>=9  Then NowPage=9
                Log("NowPage=" & NowPage)
                hsvTimer.Enabled = True
            Else 
                Log("<==" )
                NowPage=NowPage-1
                If NowPage<0 Then NowPage=0
                Log("NowPage=" & NowPage)
                hsvTimer.Enabled = True
            End If
        Case 2    ' ACTION_MOVE
    End Select
    Return False
End Sub

Private Sub hsvTimer_Tick
    hsvTimer.Enabled = False
    hsview.ScrollPosition = NowPage * hsview.Width
End Sub
75826.jpg
 

Jones Hone

Active Member
Licensed User
Longtime User
I want slide once to scroll one page.
In my code, I slide HorizontalScrollView can achieve my purpose.
But slide the button can't achieve my purpose.
Ex: Now,on the screen is as follows:
[button0] [button1] [button2]
silde right, on the screen is as follows:
[button3] [button4] [button5]
silde right, on the screen is as follows:
[button6] [button7] [button8]
silde left, on the screen is as follows:
[button3] [button4] [button5]

and button_Click event can be triggered.
 
Last edited:
Upvote 0
Top