如何防止ScrollView拦截其背后视图的单击/触摸事件? [英] How to prevent ScrollView from intercepting click/touch events of the view behind it?
问题描述
我在FrameLayout中有一个ScrollView和ImageView.ImageView位于滚动视图的后面
I have a ScrollView and an ImageView inside a FrameLayout. The ImageView is behind the scroll view
我的ScrollView有一个透明空间(LinearLayout s_layout_transparent,高度为925px).
My ScrollView have a transparent space (LinearLayout s_layout_transparent with 925px height).
因此可以在此透明空间中看到我的ImageView ,但不能单击 .
So my ImageView can be seen through this transparent space but can not be click.
我尝试添加一些值(android:clickable ="false" android:focusable ="android:focusableInTouchMode =" false)滚动视图以防止其拦截ImageView,但这根本不起作用.
I have tried to add some value (android:clickable="false" android:focusable=" android:focusableInTouchMode="false") to scroll view to prevent it intercepts the click envent of the ImageView but this not work at all.
这是我的布局:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:gravity="top|center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="10dp"
>
<ImageView
android:visibility="visible"
android:id="@+id/s_imgv_splash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/temp_detail_screen_splash"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
</LinearLayout>
<com.dreambox.android.saven.Views.ScrollView
android:id="@+id/s_scrollview_event_detail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:visibility="visible"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false">
<LinearLayout
android:id="@+id/s_layout_transparent"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="925px"
android:orientation="horizontal"
android:background="@color/trasparent"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false">
</LinearLayout>
<LinearLayout...>
<LinearLayout...>
</LinearLayout>
</com.dreambox.android.saven.Views.ScrollView>
</FrameLayout>
推荐答案
如果您可以用一个空视图填充透明部分(我们称其为dummyView),则可以执行类似的操作...
if you can fill the transparent parts with an empty view (lets call it dummyView), you can do something like...
dummyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
// pass on the touch event to the ImageView
s_imgv_splash.dispatchTouchEvent(event);
// returning true because we handled the event
return true;
}
});
这篇关于如何防止ScrollView拦截其背后视图的单击/触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!