Abolfazl R
Abolfazl R

Reputation: 41

how to make an scale animation for decreasing view size(a bit)

here is my XML code:

   <?xml version="1.0" encoding="utf-8"?>
        <set xmlns:android="http://schemas.android.com/apk/res/android">
            <scale
                android:toXScale="99%"
                android:toYScale="99%"
         />
        </set>

i want to add a touch effect by resizing view(i have some card views in layout). but my code is wrong!

thanks in advance

Upvotes: 2

Views: 529

Answers (1)

Sarthak Gandhi
Sarthak Gandhi

Reputation: 2170

You can use this :

view.setOnTouchListener(new View.OnTouchListener(){

@Override
public boolean onTouch(View view,MotionEvent motionEvent){
    if(motionEvent.getAction()==MotionEvent.ACTION_DOWN){
    view.animate().scaleX(0.9f).scaleY(0.9f).setDuration(200);
    }
    else if(motionEvent.getAction()==MotionEvent.ACTION_UP){
    view.animate().scaleX(1f).scaleY(1f).setDuration(200);
    }
    return false;
  }
});

Hope this helps.

Upvotes: 2

Related Questions