Note that there are some explanatory texts on larger screens.

plurals
  1. POFrameLayout onClick for overlapping images on Android
    primarykey
    data
    text
    <p>First I thought that the problem will be very easy to solve, but it proved to be a challenge.</p> <p><strong>Scenario</strong> One FrameLayout and two ImageViews, one over the other. The first images has a Translate animation and a onClick event. Let's translate this in something practical: the Framelayout has one Rabbit image and a Bush image. The Rabbit has a translate animation so it moves out of the bush. As soon as the rabbit becomes visible, the user can tap on it. Unfortunately this does not work as intended. Even if the rabbit is not visible (being behind the bush) if the user taps on the bush, the click event of the rabbit fires. I tried to add onClick event (that doesn't do anything) for the bush image, but now only this one fires, and the rabbit ones doesn't.</p> <p><strong>Code</strong></p> <p>Animation</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0%" android:toXDelta="100%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="25000" android:zAdjustment="top" /&gt; </code></pre> <p>Layout</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layBackground" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="@drawable/someimage"&gt; &lt;ImageView android:id="@+id/imgAfterBush" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|left" android:layout_marginLeft="50dip" android:onClick="imgAfterBushOnClick"/&gt; &lt;ImageView android:id="@+id/imgBush" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bush" android:layout_gravity="bottom|left" /&gt; &lt;/FrameLayout&gt; </code></pre> <p>I want the onClick event of the Rabbit image to fire only when it is visible. Any solutions ? Thank you. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload