android - Ignore touches in overlay view -


i have layout pretty simple - has 2 views: list view , fully-covering "overlay" view; below example:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"               android:orientation="vertical"               android:layout_width="match_parent"               android:layout_height="match_parent">      <listview             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:id="@+id/listview"/>      <relativelayout             android:layout_width="fill_parent"             android:layout_height="fill_parent">          <imageview                 android:layout_width="360dp"                 android:layout_height="270dp"                 android:id="@+id/imageview"                 android:layout_centerinparent="true"                 android:background="#8888"/>          <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="this text"                 android:id="@+id/button"                 android:layout_below="@+id/imageview"                 android:layout_centerhorizontal="true"/>     </relativelayout>  </relativelayout> 

i made overlay view little simpler mine is, there no views should want have touch (that is, no buttons or scrollable areas) - linearlayout's scattered about). i'd ignore touches not in layout in subviews of layout well. view want receive touches listview.

i've implemented in simple way first - similar above - , touches never through underlying listview (it doesn't scroll when drag).

i don't have first clue how android. answer (https://stackoverflow.com/a/9462091/875486) points using flags (specifically flag_not_touchable , flag_not_focusable) can't quite figure out how use flags.

why don't assign id in xml relativelayout , give ontouchlistener not in code. override underlying views without listeners.

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"               android:id="@+id/layout"               android:orientation="vertical"               android:layout_width="match_parent"               android:layout_height="match_parent">      <listview             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:id="@+id/listview"/>      <relativelayout             android:layout_width="fill_parent"             android:layout_height="fill_parent">          <imageview                 android:layout_width="360dp"                 android:layout_height="270dp"                 android:id="@+id/imageview"                 android:layout_centerinparent="true"                 android:background="#8888"/>          <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="this text"                 android:id="@+id/button"                 android:layout_below="@+id/imageview"                 android:layout_centerhorizontal="true"/>     </relativelayout>  </relativelayout> 

...

relativelayout mlayout = (relativelayout) findviewbyid(r.id.layout); mlayout.setontouchlistener(new ontouchlistener() {          @override         public boolean ontouch(view v, motionevent event) {             // intercept touch events not passed underlying views.             return true;         }     });  listview mlistview = (listview) findviewbyid(r.id.listview); mlistview.setontouchlistener(new ontouchlistener() {          @override         public boolean ontouch(view v, motionevent event) {             //do stuff         }     });   

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -