Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The click-sensitive area does not change after animating and interactive view in android

Kindda weird situation...

I have an ImageView which has a click interaction associated with it.

In the code I change the position of the ImageView via an animation.

But when the animation finishes the clickable area is still in the original spot of the ImageView (I can actually tap that area and see the click being handled).

Did some research, seems that the animation only moves the view pixels around, the view remains where it originally was.

As a bit of a criticism to android - this is not an intuitive design/implementation. This does not conform with "What you see is what you get" criteria.

And my question is

is there a way (except toggling between two different ImageViews) to make the clickable area move to where the view pixels are?

My layout and animation xml structures are as follows.

layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keywords_layer"
    android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0dp"
android:padding="0dp"
android:orientation="vertical"
android:visibility="gone"
>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="35dp" 
    >
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="35dp"
        android:layout_centerInParent="true"
        android:adjustViewBounds="false"
        android:scaleType="fitXY"
        android:src="@drawable/keyword_bar_handle"
    />
    <ImageView
        android:id="@+id/bar_handle"
        android:layout_width="45dp"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:adjustViewBounds="false"
        android:scaleType="fitXY"
    />
</RelativeLayout>
<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="@dimen/browser_address_bar_1_5_height"
    android:layout_margin="0dp"
    android:padding="0dp"
    android:background="@drawable/keyword_bar_bg"
    android:scrollbars="none"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="@dimen/browser_address_bar_1_5_height"
        android:layout_margin="0dp"
        android:padding="0dp" 
    />
</HorizontalScrollView>

Animation:

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fillEnabled="true"
    android:fillAfter="true">
<translate
    android:fromYDelta="60"
    android:toYDelta="0"
    android:duration="300"
/>
    </set>

In here the layout is aligned to the bottom of the screen and needs to be smoothly toggled - hidden or shown. "bar_handle" ImageView handles the toggling. "bar_handle" is inside the animated structure, so it moves with it.

Thanks for any help.

like image 380
Nar Gar Avatar asked Jul 30 '12 02:07

Nar Gar


1 Answers

The View Animation don't change the actually position of the view, so if you want to really change the position, try to use scroll it yourself

for example: use scrollTo, scrollBy or if you want it scroll automatically, you can use scroller to help you do that.

like image 150
Changwei Yao Avatar answered Oct 21 '22 00:10

Changwei Yao