Shailendra
Shailendra

Reputation: 325

How to scale click/touch area of a view after applying ScaleAnimation in android?

I haven't found any solution regarding how to scale the touch area of a view after applying ScaleAnimation, this animation really change the scale of that view but not the touch area of that view .The touch area remains the same. Here is my sample code:

package com.xyz;

public class XyzActivity extends Activity {
int zoomLevel = 1;
int zoomNext = 2;
Button btn = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    btn = (Button)findViewById(R.id.button1);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            AnimationSet set = new AnimationSet(false);
            ScaleAnimation anim = new ScaleAnimation(zoomLevel, zoomNext, zoomLevel, zoomNext);
            set.addAnimation(anim);
            set.setDuration(0);
            set.setFillEnabled(true);
            set.setFillAfter(true);
            v.startAnimation(set);
            zoomLevel += zoomNext;
            zoomNext = zoomLevel - zoomNext;
            zoomLevel-=zoomNext;
        }
    });
   }

  }

And tha xml is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
    <Button android:text="Button" android:id="@+id/button1" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</RelativeLayout>

What I do please suggest me....

Upvotes: 5

Views: 2075

Answers (1)

Mattias Isegran Bergander
Mattias Isegran Bergander

Reputation: 11909

An animation only moves the pixels around. You can add a listener to check for the end of the animation and actually move the widdget/button or subclass the widget/button (or the layout it is inside migth be easier depnding on the animation) and change the touch checks (ontouch).

Or at animation end you can hide the original view and show an "new" view. That's easier to understand in the layout xml as well (you can set them to hidden there). Depends on the animation details.

Upvotes: 1

Related Questions