Android Question Google Maps vs Custom List View scrolling

AHilton

Active Member
Licensed User
Longtime User
I have a Google Maps V2 in a Custom List View and can't scroll vertically within the map because Custom List View is picking it up and scrolling that instead. The map picks up the horizontal scrolling, just fine.

How do I get the map to scroll and not the custom list view?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
upload_2016-11-30_10-57-10.png


Solution based on: http://stackoverflow.com/questions/...oogle-maps-scroll-properly-inside-scroll-view

I cannot upload the project as I'm using an alpha version of B4A and the layout is not compatible with older versions of B4A.

1. Create a layout file named CLV with the CustomListView (named CLV1).
2. Create a layout with the map and put an ImageView above it. Make sure that are anchored to both sides.

The trick is to disable the inner ScrollView when the user touches the transparent ImageView:
B4X:
'Activity module
Sub Process_Globals

End Sub

Sub Globals
   Private gmap As GoogleMap
   Private MapFragment1 As MapFragment
   Private CLV1 As CustomListView
   Private ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("CLV")
   CLV1.AddTextItem($"s ;ldfk ;sldf wef
w eglw gkw
gkw;elg w
eg wekfer
re
g
erg
erg
g lwkgl;w keg
;we lkgw;l g"$, "")
   Dim p As Panel
   p.Initialize("")
   Activity.AddView(p, 0, 0, 100%x, 300dip) 'just to set the panel dimensions
   p.LoadLayout("1")
   p.RemoveView
   CLV1.Add(p, p.Height, "")
   CLV1.AddTextItem($"s ;ldfk ;sldf wef
w eglw gkw
gkw;elg w
eg wekfer
re
g
erg
erg
g lwkgl;w keg
;we lkgw;l g"$, "")
   Dim r As Reflector
   r.Target = ImageView1
   r.SetOnTouchListener("ImageView1_Touch")
   ImageView1.Color = Colors.Transparent
   If MapFragment1.IsGooglePlayServicesAvailable = False Then
     ToastMessageShow("Please install Google Play Services.", True)
   End If
End Sub

Sub ImageView1_Touch (ViewTag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
   Dim sv As ScrollView = CLV1.AsView
   Dim jo As JavaObject = sv
   jo.RunMethod("requestDisallowInterceptTouchEvent", Array(Action = Activity.ACTION_DOWN Or Action = Activity.ACTION_UP))
   Return Action = Activity.ACTION_UP
End Sub

Sub MapFragment1_Ready
   gmap = MapFragment1.GetMap
   
End Sub
 
Upvote 0
Top