Android - 通过部分 ScrollView 传递触摸事件
Android - Pass a touch event through part of ScrollView
如果您很了解 android,这应该是一个简单的答案。我正在设计一个需要实现 Google MapFragment 的应用程序。我想在滚动视图中的下方有一个文本区域,如下所示。但是,我想给文本提供向上滚动 OVER 地图的效果(非常类似于android play store effect found here.
为了实现这一点,我决定让滚动视图从地图的顶部开始,并简单地在地图上放置一个不可见的垫片,使文本看起来像是从下方开始的。通过将地图视图放在滚动视图后面,触摸事件当然是 'stolen' (所以我不能移动地图,放大等)。我的想法是,可能有一种方法可以让 spacer 的触摸事件流过 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>
感谢您的回答。如果有任何困惑,请询问。
我在这里解决了我自己的问题。我没有尝试让地图在 ScrollView 后面工作,而是简单地定义了一些情况,在这些情况下我可以更改地图的 z-index 以便它可以访问。例如,当我的 ScrollView 的 scrollY 值为 0 时,我允许地图位于顶部。我还添加了一个子句,允许用户单击分隔符(覆盖地图)将视图向下滚动到底部,从而使地图再次出现在前面。感谢帮助
如果您很了解 android,这应该是一个简单的答案。我正在设计一个需要实现 Google MapFragment 的应用程序。我想在滚动视图中的下方有一个文本区域,如下所示。但是,我想给文本提供向上滚动 OVER 地图的效果(非常类似于android play store effect found here.
为了实现这一点,我决定让滚动视图从地图的顶部开始,并简单地在地图上放置一个不可见的垫片,使文本看起来像是从下方开始的。通过将地图视图放在滚动视图后面,触摸事件当然是 'stolen' (所以我不能移动地图,放大等)。我的想法是,可能有一种方法可以让 spacer 的触摸事件流过 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>
感谢您的回答。如果有任何困惑,请询问。
我在这里解决了我自己的问题。我没有尝试让地图在 ScrollView 后面工作,而是简单地定义了一些情况,在这些情况下我可以更改地图的 z-index 以便它可以访问。例如,当我的 ScrollView 的 scrollY 值为 0 时,我允许地图位于顶部。我还添加了一个子句,允许用户单击分隔符(覆盖地图)将视图向下滚动到底部,从而使地图再次出现在前面。感谢帮助