Android: clicking issue of overlapping imageViews with transparent background -
i have 2 clickable imageviews partially overlap each other, let's big 1 @ bottom base , small 1 on top right corner of it. sample view: this. black circle have problem getting big image's listener.
the problem is, transparent area invisible still there, lead ontouch action not "accurate". e.g. clicking on overlapping area, small image transparent , big isn't, small image detected, want big image detected.
using ontouchlistener catch colour make transparent areas not clickable won't neither.
how can solve please?
imageview big, small; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_seventh); big = (imageview) findviewbyid(r.id.imageviewbig); small = (imageview) findviewbyid(r.id.imageviewsmall); big.setontouchlistener(this); small.setontouchlistener(this); } @override public boolean ontouch(view v, motionevent event) { if (event.getaction() == motionevent.action_down) { switch (v.getid()) { case r.id.imageviewbig: toast.maketext(this, "big", toast.length_short).show(); break; case r.id.imageviewsmall: toast.maketext(this, "small", toast.length_short).show(); break; default: toast.maketext(this, "none", toast.length_short).show(); } } return true; }
xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.gamification.gamificationpagestudy.progressbar.seventhactivity"> <imageview android:id="@+id/imageviewbig" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:clickable="true" android:src="@drawable/germany" /> <imageview android:id="@+id/imageviewsmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignend="@+id/imageviewbig" android:layout_alignright="@+id/imageviewbig" android:layout_aligntop="@+id/imageviewbig" android:clickable="true" android:src="@drawable/brazil" /> </relativelayout>
thanks dreo suggestion :d
continue ontouchlistner transparent area, touched view's mid point check whether bottom left or right area touched, action, in case bottom left corner gridview's item @ position 0, , bottom right corner item @ position 1:
if (color == color.transparent) { int touchx = (int) event.getx(); int touchy = (int) event.gety(); int middle_width = v.getwidth()/2; int middle_height = v.getheight()/2; if (touchx < middle_width && touchy > middle_height) // bottom left toast.maketext(gamificationmainactivity.this, gvadapter.getitem(0), toast.length_short).show(); else if (touchx > middle_width && touchy > middle_height) // bottom right toast.maketext(gamificationmainactivity.this, gvadapter.getitem(1), toast.length_short).show(); return true; } else { //... }
Comments
Post a Comment