When a view is overlapping another view then the hidden view will not get any touch event as the view on top consumes the touch event. If you want to the hidden view to receive the touch event then you have to manually pass the touch event from the top view to the hidden view.
Here there are two possibilities:
- You want the touch event to be shared by both the view: In this case after passing the touch event to the hidden view indicate android that touch event has not been consumed by returning false from the onTouch() method of the top view.
- You want the touch event to be handled by only the hidden view: In this case after passing the touch event to the hidden view indicate android that the touch event been consumed by returning true from the onTouch() method of the top view.
Here is a sample code for this:
btn.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch (View v, MotionEvent event)
{
list.onTouchEvent(event);
return true; // return true if touch event is consumed else return false
}
});
XML for this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/shape" >
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000" >
</ListView>
<Button
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#88cc0000"
android:layout_alignParentTop="true"
android:onClick="showMe" />
</RelativeLayout>
Here Button is hiding the list view still the list will scroll as the touch event is passed to the below layout.
I hope this will help. :)