Search code examples
androidxmlanimationscale

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


Solution

  • 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.