Android - Drag and Drop - Animation shadow to destination











up vote
25
down vote

favorite
5












I want to animate a ShadowView to some coordinates (to destination view).



I'm using D&D and if user drops (DragEvent.ACTION_DROP) then the view in some area I want to animate the view (from the drop location) to some destination view.



I don't want to animate view from the source location but want to do from the DROP location.



I tried a lot of things but nothing works. How can I get access to the ShadowView? This also not working:



EventDragShadowBuilder.getView()


I think TranslateAnimation should work for this but I need access to the "shadow" view during the D&D.



Image: enter image description here










share|improve this question




















  • 1




    I don't think you can get access to ShadowView. If you can get the dropped location, you could create a duplicate View yourself with same background as the ShadowView and animate this duplicate view to destination giving the illusion that ShdowView itself is moving.
    – Abhishek V
    Oct 21 '16 at 5:35















up vote
25
down vote

favorite
5












I want to animate a ShadowView to some coordinates (to destination view).



I'm using D&D and if user drops (DragEvent.ACTION_DROP) then the view in some area I want to animate the view (from the drop location) to some destination view.



I don't want to animate view from the source location but want to do from the DROP location.



I tried a lot of things but nothing works. How can I get access to the ShadowView? This also not working:



EventDragShadowBuilder.getView()


I think TranslateAnimation should work for this but I need access to the "shadow" view during the D&D.



Image: enter image description here










share|improve this question




















  • 1




    I don't think you can get access to ShadowView. If you can get the dropped location, you could create a duplicate View yourself with same background as the ShadowView and animate this duplicate view to destination giving the illusion that ShdowView itself is moving.
    – Abhishek V
    Oct 21 '16 at 5:35













up vote
25
down vote

favorite
5









up vote
25
down vote

favorite
5






5





I want to animate a ShadowView to some coordinates (to destination view).



I'm using D&D and if user drops (DragEvent.ACTION_DROP) then the view in some area I want to animate the view (from the drop location) to some destination view.



I don't want to animate view from the source location but want to do from the DROP location.



I tried a lot of things but nothing works. How can I get access to the ShadowView? This also not working:



EventDragShadowBuilder.getView()


I think TranslateAnimation should work for this but I need access to the "shadow" view during the D&D.



Image: enter image description here










share|improve this question















I want to animate a ShadowView to some coordinates (to destination view).



I'm using D&D and if user drops (DragEvent.ACTION_DROP) then the view in some area I want to animate the view (from the drop location) to some destination view.



I don't want to animate view from the source location but want to do from the DROP location.



I tried a lot of things but nothing works. How can I get access to the ShadowView? This also not working:



EventDragShadowBuilder.getView()


I think TranslateAnimation should work for this but I need access to the "shadow" view during the D&D.



Image: enter image description here







android animation drag-and-drop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 8 at 12:36









Mark

3,68631331




3,68631331










asked Oct 12 '16 at 12:55









Pepa Zapletal

1,05332150




1,05332150








  • 1




    I don't think you can get access to ShadowView. If you can get the dropped location, you could create a duplicate View yourself with same background as the ShadowView and animate this duplicate view to destination giving the illusion that ShdowView itself is moving.
    – Abhishek V
    Oct 21 '16 at 5:35














  • 1




    I don't think you can get access to ShadowView. If you can get the dropped location, you could create a duplicate View yourself with same background as the ShadowView and animate this duplicate view to destination giving the illusion that ShdowView itself is moving.
    – Abhishek V
    Oct 21 '16 at 5:35








1




1




I don't think you can get access to ShadowView. If you can get the dropped location, you could create a duplicate View yourself with same background as the ShadowView and animate this duplicate view to destination giving the illusion that ShdowView itself is moving.
– Abhishek V
Oct 21 '16 at 5:35




I don't think you can get access to ShadowView. If you can get the dropped location, you could create a duplicate View yourself with same background as the ShadowView and animate this duplicate view to destination giving the illusion that ShdowView itself is moving.
– Abhishek V
Oct 21 '16 at 5:35












4 Answers
4






active

oldest

votes

















up vote
1
down vote













First implement onTouchlistener on the view



llDragable.setOnTouchListener(this);


Make a view draggable



@Override
public boolean onTouch(View view, MotionEvent event) {
float dX = 0;
float dY = 0;
switch (view.getId()){
case R.id.dragableLayout :{
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
dX = view.getX() - event.getRawX();
dY = view.getY() - event.getRawY();
lastAction = MotionEvent.ACTION_DOWN;
break;

case MotionEvent.ACTION_MOVE:
view.setY(event.getRawY() + dY);
view.setX(event.getRawX() + dX);
lastAction = MotionEvent.ACTION_MOVE;
break;

case MotionEvent.ACTION_UP:
//Animate
animate();
if (lastAction == MotionEvent.ACTION_DOWN)
//Toast.makeText(DraggableView.this, "Clicked!", Toast.LENGTH_SHORT).show();
break;

default:
return false;
}
return true;
}
}
return false;
}


Then you can use object animator at case MotionEvent.ACTION_UP using object animation . You need to have the position of the destination.



private void animate() {
Path path = new Path();
path.moveTo(destinationX, destinationY);
path.lineTo(destinationX, destinationY);
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mButton, View.X, View.Y, path);
objectAnimator.setDuration(duration);
objectAnimator.setInterpolator(new LinearInterpolator());
objectAnimator.start();
}





share|improve this answer




























    up vote
    0
    down vote













    One possible thing could be



    once the drag event has finished, you can move the "view" to the location of the drop and then you can start an animation to move the view from the dropped location to the destination.



    Keep in mind here the drag shadow is not being animated but the view itself is being animated.






    share|improve this answer




























      up vote
      0
      down vote













      As a workaround, you can try to add a selector with transparent and black-gradient drawables, depended on appropriate state. In this case you will decide, when your "shadow" should be shown and when it should be gone.



      Here is a question about "shadow" bordered layouts:
      Android LinearLayout : Add border with shadow around a linearLayout



      Don't sure, is it a good way... But it might work.
      Good luck!






      share|improve this answer




























        up vote
        0
        down vote













        Create a duplicate view of the one you are dragging. Once drag ends, you get the location or drop off co-ordinates of the view. Once this happens, set the visibility of your "real" view to View.INVISIBLE. Then set the x and y of the temp invisible view to that of the drop-off point and make it visible. After that, create a translate animation that animates the temp view to the desired position, and don't forget to set the setFillEnabled and setFillAfter properties of the translate animation to true.






        share|improve this answer





















          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39999169%2fandroid-drag-and-drop-animation-shadow-to-destination%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          First implement onTouchlistener on the view



          llDragable.setOnTouchListener(this);


          Make a view draggable



          @Override
          public boolean onTouch(View view, MotionEvent event) {
          float dX = 0;
          float dY = 0;
          switch (view.getId()){
          case R.id.dragableLayout :{
          switch (event.getActionMasked()) {
          case MotionEvent.ACTION_DOWN:
          dX = view.getX() - event.getRawX();
          dY = view.getY() - event.getRawY();
          lastAction = MotionEvent.ACTION_DOWN;
          break;

          case MotionEvent.ACTION_MOVE:
          view.setY(event.getRawY() + dY);
          view.setX(event.getRawX() + dX);
          lastAction = MotionEvent.ACTION_MOVE;
          break;

          case MotionEvent.ACTION_UP:
          //Animate
          animate();
          if (lastAction == MotionEvent.ACTION_DOWN)
          //Toast.makeText(DraggableView.this, "Clicked!", Toast.LENGTH_SHORT).show();
          break;

          default:
          return false;
          }
          return true;
          }
          }
          return false;
          }


          Then you can use object animator at case MotionEvent.ACTION_UP using object animation . You need to have the position of the destination.



          private void animate() {
          Path path = new Path();
          path.moveTo(destinationX, destinationY);
          path.lineTo(destinationX, destinationY);
          ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mButton, View.X, View.Y, path);
          objectAnimator.setDuration(duration);
          objectAnimator.setInterpolator(new LinearInterpolator());
          objectAnimator.start();
          }





          share|improve this answer

























            up vote
            1
            down vote













            First implement onTouchlistener on the view



            llDragable.setOnTouchListener(this);


            Make a view draggable



            @Override
            public boolean onTouch(View view, MotionEvent event) {
            float dX = 0;
            float dY = 0;
            switch (view.getId()){
            case R.id.dragableLayout :{
            switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
            dX = view.getX() - event.getRawX();
            dY = view.getY() - event.getRawY();
            lastAction = MotionEvent.ACTION_DOWN;
            break;

            case MotionEvent.ACTION_MOVE:
            view.setY(event.getRawY() + dY);
            view.setX(event.getRawX() + dX);
            lastAction = MotionEvent.ACTION_MOVE;
            break;

            case MotionEvent.ACTION_UP:
            //Animate
            animate();
            if (lastAction == MotionEvent.ACTION_DOWN)
            //Toast.makeText(DraggableView.this, "Clicked!", Toast.LENGTH_SHORT).show();
            break;

            default:
            return false;
            }
            return true;
            }
            }
            return false;
            }


            Then you can use object animator at case MotionEvent.ACTION_UP using object animation . You need to have the position of the destination.



            private void animate() {
            Path path = new Path();
            path.moveTo(destinationX, destinationY);
            path.lineTo(destinationX, destinationY);
            ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mButton, View.X, View.Y, path);
            objectAnimator.setDuration(duration);
            objectAnimator.setInterpolator(new LinearInterpolator());
            objectAnimator.start();
            }





            share|improve this answer























              up vote
              1
              down vote










              up vote
              1
              down vote









              First implement onTouchlistener on the view



              llDragable.setOnTouchListener(this);


              Make a view draggable



              @Override
              public boolean onTouch(View view, MotionEvent event) {
              float dX = 0;
              float dY = 0;
              switch (view.getId()){
              case R.id.dragableLayout :{
              switch (event.getActionMasked()) {
              case MotionEvent.ACTION_DOWN:
              dX = view.getX() - event.getRawX();
              dY = view.getY() - event.getRawY();
              lastAction = MotionEvent.ACTION_DOWN;
              break;

              case MotionEvent.ACTION_MOVE:
              view.setY(event.getRawY() + dY);
              view.setX(event.getRawX() + dX);
              lastAction = MotionEvent.ACTION_MOVE;
              break;

              case MotionEvent.ACTION_UP:
              //Animate
              animate();
              if (lastAction == MotionEvent.ACTION_DOWN)
              //Toast.makeText(DraggableView.this, "Clicked!", Toast.LENGTH_SHORT).show();
              break;

              default:
              return false;
              }
              return true;
              }
              }
              return false;
              }


              Then you can use object animator at case MotionEvent.ACTION_UP using object animation . You need to have the position of the destination.



              private void animate() {
              Path path = new Path();
              path.moveTo(destinationX, destinationY);
              path.lineTo(destinationX, destinationY);
              ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mButton, View.X, View.Y, path);
              objectAnimator.setDuration(duration);
              objectAnimator.setInterpolator(new LinearInterpolator());
              objectAnimator.start();
              }





              share|improve this answer












              First implement onTouchlistener on the view



              llDragable.setOnTouchListener(this);


              Make a view draggable



              @Override
              public boolean onTouch(View view, MotionEvent event) {
              float dX = 0;
              float dY = 0;
              switch (view.getId()){
              case R.id.dragableLayout :{
              switch (event.getActionMasked()) {
              case MotionEvent.ACTION_DOWN:
              dX = view.getX() - event.getRawX();
              dY = view.getY() - event.getRawY();
              lastAction = MotionEvent.ACTION_DOWN;
              break;

              case MotionEvent.ACTION_MOVE:
              view.setY(event.getRawY() + dY);
              view.setX(event.getRawX() + dX);
              lastAction = MotionEvent.ACTION_MOVE;
              break;

              case MotionEvent.ACTION_UP:
              //Animate
              animate();
              if (lastAction == MotionEvent.ACTION_DOWN)
              //Toast.makeText(DraggableView.this, "Clicked!", Toast.LENGTH_SHORT).show();
              break;

              default:
              return false;
              }
              return true;
              }
              }
              return false;
              }


              Then you can use object animator at case MotionEvent.ACTION_UP using object animation . You need to have the position of the destination.



              private void animate() {
              Path path = new Path();
              path.moveTo(destinationX, destinationY);
              path.lineTo(destinationX, destinationY);
              ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mButton, View.X, View.Y, path);
              objectAnimator.setDuration(duration);
              objectAnimator.setInterpolator(new LinearInterpolator());
              objectAnimator.start();
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 19 at 7:21









              Rabindra Khadka

              54213




              54213
























                  up vote
                  0
                  down vote













                  One possible thing could be



                  once the drag event has finished, you can move the "view" to the location of the drop and then you can start an animation to move the view from the dropped location to the destination.



                  Keep in mind here the drag shadow is not being animated but the view itself is being animated.






                  share|improve this answer

























                    up vote
                    0
                    down vote













                    One possible thing could be



                    once the drag event has finished, you can move the "view" to the location of the drop and then you can start an animation to move the view from the dropped location to the destination.



                    Keep in mind here the drag shadow is not being animated but the view itself is being animated.






                    share|improve this answer























                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      One possible thing could be



                      once the drag event has finished, you can move the "view" to the location of the drop and then you can start an animation to move the view from the dropped location to the destination.



                      Keep in mind here the drag shadow is not being animated but the view itself is being animated.






                      share|improve this answer












                      One possible thing could be



                      once the drag event has finished, you can move the "view" to the location of the drop and then you can start an animation to move the view from the dropped location to the destination.



                      Keep in mind here the drag shadow is not being animated but the view itself is being animated.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 30 '17 at 17:53









                      Samarth S

                      413




                      413






















                          up vote
                          0
                          down vote













                          As a workaround, you can try to add a selector with transparent and black-gradient drawables, depended on appropriate state. In this case you will decide, when your "shadow" should be shown and when it should be gone.



                          Here is a question about "shadow" bordered layouts:
                          Android LinearLayout : Add border with shadow around a linearLayout



                          Don't sure, is it a good way... But it might work.
                          Good luck!






                          share|improve this answer

























                            up vote
                            0
                            down vote













                            As a workaround, you can try to add a selector with transparent and black-gradient drawables, depended on appropriate state. In this case you will decide, when your "shadow" should be shown and when it should be gone.



                            Here is a question about "shadow" bordered layouts:
                            Android LinearLayout : Add border with shadow around a linearLayout



                            Don't sure, is it a good way... But it might work.
                            Good luck!






                            share|improve this answer























                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              As a workaround, you can try to add a selector with transparent and black-gradient drawables, depended on appropriate state. In this case you will decide, when your "shadow" should be shown and when it should be gone.



                              Here is a question about "shadow" bordered layouts:
                              Android LinearLayout : Add border with shadow around a linearLayout



                              Don't sure, is it a good way... But it might work.
                              Good luck!






                              share|improve this answer












                              As a workaround, you can try to add a selector with transparent and black-gradient drawables, depended on appropriate state. In this case you will decide, when your "shadow" should be shown and when it should be gone.



                              Here is a question about "shadow" bordered layouts:
                              Android LinearLayout : Add border with shadow around a linearLayout



                              Don't sure, is it a good way... But it might work.
                              Good luck!







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Sep 5 '17 at 20:53









                              Ihor Martyniuk

                              14




                              14






















                                  up vote
                                  0
                                  down vote













                                  Create a duplicate view of the one you are dragging. Once drag ends, you get the location or drop off co-ordinates of the view. Once this happens, set the visibility of your "real" view to View.INVISIBLE. Then set the x and y of the temp invisible view to that of the drop-off point and make it visible. After that, create a translate animation that animates the temp view to the desired position, and don't forget to set the setFillEnabled and setFillAfter properties of the translate animation to true.






                                  share|improve this answer

























                                    up vote
                                    0
                                    down vote













                                    Create a duplicate view of the one you are dragging. Once drag ends, you get the location or drop off co-ordinates of the view. Once this happens, set the visibility of your "real" view to View.INVISIBLE. Then set the x and y of the temp invisible view to that of the drop-off point and make it visible. After that, create a translate animation that animates the temp view to the desired position, and don't forget to set the setFillEnabled and setFillAfter properties of the translate animation to true.






                                    share|improve this answer























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      Create a duplicate view of the one you are dragging. Once drag ends, you get the location or drop off co-ordinates of the view. Once this happens, set the visibility of your "real" view to View.INVISIBLE. Then set the x and y of the temp invisible view to that of the drop-off point and make it visible. After that, create a translate animation that animates the temp view to the desired position, and don't forget to set the setFillEnabled and setFillAfter properties of the translate animation to true.






                                      share|improve this answer












                                      Create a duplicate view of the one you are dragging. Once drag ends, you get the location or drop off co-ordinates of the view. Once this happens, set the visibility of your "real" view to View.INVISIBLE. Then set the x and y of the temp invisible view to that of the drop-off point and make it visible. After that, create a translate animation that animates the temp view to the desired position, and don't forget to set the setFillEnabled and setFillAfter properties of the translate animation to true.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jul 7 at 10:31









                                      C Colutions

                                      165




                                      165






























                                           

                                          draft saved


                                          draft discarded



















































                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39999169%2fandroid-drag-and-drop-animation-shadow-to-destination%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Costa Masnaga

                                          Fotorealismo

                                          Sidney Franklin