0

This should be an easy answer if you know android well. I am designing an app that requires implementing a Google MapFragment. I want to have an area of text below it inside a scrollview as shown below. However, I want to give the text the effect of scrolling up OVER the map (very similar to the android play store effect found here.

Not scrolled view Half scrolled view

To implement this I decided to make the scrollview start at the top of the map and simply put an invisible spacer over the map to give the appearance that the text starts below. By putting the map view behind the scrollview, the touch event is of course 'stolen' (so I can't move the map around, zoom in etc.). My thought was that there might be a way to let the spacer's touch events bleed through the ScrollView and be intercepted by the map view. Is this possible? Or is there a better way I should implement this?

My code goes something like this:

<!-- This will be the map (dynamically loaded in) -->
<fragment 
    ...
    android:layout_height="200dp"
    android:id="@+id/map"
    android:layout_below="@+id/searchBox"
    ...
/>

<!-- Note: starts under searchBox, just like @+id/map does -->
<ScrollView
    ...
    android:layout_below="@+id/searchBox"
    ...
>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <!-- This is the spacer. Covers the map so that the content can be positioned under it (thus content is under the map as well) -->
        <View
            android:layout_width="wrap_content"
            android:layout_height="200dp"
            android:id="@+id/mapSpacer"/>

        ... The actual text content goes here

    </RelativeLayout>
</ScrollView>

I appreciate the answers. If anything is confusing please ask.

Community
  • 1
  • 1
JFakult
  • 327
  • 1
  • 2
  • 16
  • possible duplicate of [How to capture onTouch events on two overlapping views?](http://stackoverflow.com/questions/26352459/how-to-capture-ontouch-events-on-two-overlapping-views) – joeblubaugh Jul 15 '15 at 18:40
  • You could try put android:clickable="false" on your scrollview but that probably will effect the scroll itself... but idk, try it. – Kamila Brito Jul 15 '15 at 18:43
  • Yeah that won't work: I only need the scroll event to pass through the spacer itself because I want to be able to scroll text up, as well as navigate in the map view (which requires scrolling or zooming etc.) – JFakult Jul 15 '15 at 18:46
  • You may try to use the newest design library of `CollapsingToolbarLayout`. For more details, please refer [here](http://android-developers.blogspot.com/2015/05/android-design-support-library.html), and you can get the demo [here](https://github.com/chrisbanes/cheesesquare). – bjiang Jul 16 '15 at 18:51

1 Answers1

1

I solved my own problem here. Instead of trying to get the map to work BEHIND the ScrollView, I simply defined a few cases in which I can change the z-index of the map so that it is accessible. For example, when my ScrollView's scrollY value was 0, I allow the map to sit on top. I also added in a clause allowing the user to click the spacer (covering the map) to scroll the view down to the bottom, causing the map to come to the front again. Thanks for the help

JFakult
  • 327
  • 1
  • 2
  • 16