Android Question About HorizontalScrollView touch event

Discussion in 'Android Questions' started by Jones Hone, Nov 16, 2018.

  1. Jones Hone

    Jones Hone Member Licensed 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:
    Code:
    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*3As 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+1Mod 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
    [​IMG]
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Adding a touch listener to HSV will not work. What are you trying to do?
     
  3. Jones Hone

    Jones Hone Member Licensed 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: Nov 16, 2018
  4. Erel

    Erel Administrator Staff Member Licensed User

    Why not use TabStripViewPager?
     
  5. Jones Hone

    Jones Hone Member Licensed User

    I will try again later. Thank you!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice