Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent ScrollView from intercepting click/touch events of the view behind it?

I have a ScrollView and an ImageView inside a FrameLayout. The ImageView is behind the scroll view

My ScrollView have a transparent space (LinearLayout s_layout_transparent with 925px height).

So my ImageView can be seen through this transparent space but can not be click.

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.

Here is my layout:

<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>
like image 239
NghiaDao Avatar asked Sep 15 '14 01:09

NghiaDao


People also ask

What is fillViewport in ScrollView?

fillViewport allows scrollView to extend it's height equals to the full height of device screen's height in the cases when the child of scroll view has less height.

How many views can you use within a ScrollView?

Only one view can be included in a ScrollView .

What is the difference between ScrollView and horizontal ScrollView?

ScrollView and HorizontalScrollView has same attributes, the only difference is scrollView scroll the child items in vertical direction while horizontal scroll view scroll the child items in horizontal direction.

What is the difference between ScrollView and ListView?

ScrollView is used to put different or same child views or layouts and the all can be scrolled. ListView is used to put same child view or layout as multiple items. All these items are also scrollable. Simply ScrollView is for both homogeneous and heterogeneous collection.


1 Answers

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;
    }
});
like image 179
Mahesh J Avatar answered Nov 10 '22 18:11

Mahesh J