【问题标题】:Android - Pass a touch event through part of ScrollViewAndroid - 通过部分 ScrollView 传递触摸事件
【发布时间】:2015-10-04 23:10:27
【问题描述】:

如果您对 android 非常了解,这应该是一个简单的答案。我正在设计一个需要实现 Google MapFragment 的应用程序。我想在滚动视图内有一个文本区域,如下所示。但是,我想给文本在地图上滚动的效果(非常类似于here找到的android play store效果。

为了实现这一点,我决定让滚动视图从地图顶部开始,并简单地在地图上放置一个不可见的间隔,以使文本看起来从下面开始。通过将地图视图放在滚动视图后面,触摸事件当然是“被盗”(所以我不能移动地图,放大等)。我的想法是,可能有一种方法可以让垫片的触摸事件通过 ScrollView 并被地图视图拦截。这可能吗?还是有更好的方法我应该实现它?

我的代码是这样的:

<!-- 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>

感谢您的回答。如果有什么令人困惑的地方,请询问。

【问题讨论】:

  • 您可以尝试将 android:clickable="false" 放在您的滚动视图上,但这可能会影响滚动本身...但是,请尝试一下。
  • 是的,这行不通:我只需要滚动事件通过间隔本身,因为我希望能够向上滚动文本,以及在地图视图中导航(这需要滚动或缩放等)
  • 您可以尝试使用CollapsingToolbarLayout的最新设计库。更多详情请参考here,并可以获取demohere

标签: java android google-maps scroll scrollview


【解决方案1】:

我在这里解决了我自己的问题。我没有尝试让地图在 ScrollView 后面工作,而是简单地定义了一些可以更改地图的 z-index 以使其可访问的情况。例如,当我的 ScrollView 的 scrollY 值为 0 时,我允许地图位于顶部。我还添加了一个子句,允许用户单击分隔符(覆盖地图)以将视图向下滚动到底部,从而使地图再次出现在前面。感谢您的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多