0

I have a RelativeLayout with both an ImageView and a ViewPager. It seems as though the ViewPager sits on top of the ImageView because I had an onClick listener set up for my ImageView and when I implemented the ViewPager the ImageView no longer responds to clicks. Is there any way to "click through" to the ImageView below? In general, is it possible to ignore the "top" view and allow the "bottom" view to respond to click events?

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="15dp"
        android:layout_gravity="center_horizontal">

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/feed_image_content_description"
            android:scaleType="centerCrop" />        

         <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:scaleType="centerCrop">

            <android.support.v4.view.PagerTitleStrip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                style="@style/custom_viewpagertitlestrip"
                android:layout_gravity="top" />

        </android.support.v4.view.ViewPager>
    </RelativeLayout>
Martin Erlic
  • 5,467
  • 22
  • 81
  • 153
  • 1
    Relevant question about `z-index` in `RelativeLayout`: https://stackoverflow.com/questions/2614393/defining-z-order-of-views-of-relativelayout-in-android – Nikola Nov 24 '15 at 12:43
  • I guess I could also just move the click event to the layer with the highest z-index... – Martin Erlic Nov 24 '15 at 12:46

1 Answers1

2

You may want to try to tell ViewPage (and its children) they are not clickable by setting layout attribute android:clickable="false" (I'd also perhapss set android:focusable="false" and android:focusableInTouchMode="false" from XML or call setClickable(false) from code.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141