andkulikov / Transitions-Everywhere

Set of extra Transitions on top of Jetpack Transitions Library
Apache License 2.0
4.83k stars 486 forks source link

Slide Diagonal Animation. #82

Closed root-ansh closed 6 years ago

root-ansh commented 6 years ago

Hi. Firstly, Thanks for this awesome library. I am new to animations, so While Trying the Slide() Animation, I thought of making a "Diagonal Animation"(Text going from centre to left-bottom) by adding parameter Gravity.LEFT|Gravity.BOTTOM as gravity, like this:

    Button bt3BotLeft=root3.findViewById(R.id.bt_3bottomleft);

        View.OnClickListener l=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                   case (...):
                        ....
                    case R.id.bt_3bottomleft:
                        TransitionManager.beginDelayedTransition(root3,new Slide(Gravity.LEFT|Gravity.BOTTOM));break;

                }
                tvText3.setVisibility(tvText3.getVisibility()==View.VISIBLE?View.INVISIBLE:View.VISIBLE);

            }
        };

        bt3BotLeft.setOnClickListener(l);

    }

But this caused Invalid slide direction Error :


com.work.win.anshsachdeva.animations1 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                       Process: com.work.win.anshsachdeva.animations1, PID: 26673
                                                                                       java.lang.IllegalArgumentException: Invalid slide direction
                                                                                           at com.transitionseverywhere.Slide.setSlideEdge(Slide.java:193)
                                                                                           at com.transitionseverywhere.Slide.<init>(Slide.java:152)
                                                                                           at com.work.win.anshsachdeva.animations1.MainActivity$3.onClick(MainActivity.java:92)
                                                                                           at android.view.View.performClick(View.java:4848)
                                                                                           at android.view.View$PerformClick.run(View.java:20277)
                                                                                           at android.os.Handler.handleCallback(Handler.java:815)
                                                                                           at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                                           at android.os.Looper.loop(Looper.java:194)
                                                                                           at android.app.ActivityThread.main(ActivityThread.java:5643)
                                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                                           at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

I think what i did intuitively was a wrong way of doing . So is there a right method to do so using this library? What i want to achieve is a an image of size 100*200 dp in center going towards the the bottom left edge of screen while decreasing its size on clicking.

andkulikov commented 6 years ago

Hi. Slide transitions is not supposed to work with diagonals. You can achieve for example it with Explode transition if provide epicentre somewhere into right top corner of the container. Please check samples of https://medium.com/@andkulikov/animate-all-the-things-transitions-in-android-914af5477d50

root-ansh commented 6 years ago

Thankyou . Will definitely checkout once free .