Animate/translate view from position of other viewHow to transform a FAB into a popup menu?Stop EditText from gaining focus at Activity startupView still there but not visible after being moved out by animationAndroid: Expand/collapse animationHow to scale View / ViewGroup - animate layout in a proper way?Android - Control animation of viewflipper with finger/touch?How do I animate constraint changes?Animating views beyond parent container androidView.setClipBounds() does not limit the View animation area?Android Animations - Animate view to a specific positionAnimate/Translate the View from behind another View

How do I check that users don't write down their passwords?

Why did Super-VGA offer the 5:4 1280*1024 resolution?

Motorcyle Chain needs to be cleaned every time you lube it?

How can magical vines conjured by a spell be destroyed?

What can a novel do that film and TV cannot?

Why did moving the mouse cursor cause Windows 95 to run more quickly?

How serious is plagiarism in a master’s thesis?

Should I warn my boss I might take sick leave?

Did Stalin kill all Soviet officers involved in the Winter War?

Does 5e have an equivalent of the Psychic Paper from Doctor Who?

Park the computer

2000s (or earlier) cyberpunk novel: dystopia, mega storm, omnipresent noise

How come a desk dictionary be abridged?

The Purpose of "Natu"

Is conquering your neighbors to fight a greater enemy a valid strategy?

n-level Ouroboros Quine

Is this standard Japanese employment negotiations, or am I missing something?

What is the maximum amount of diamond in one Minecraft game?

What is the shape of the upper boundary of water hitting a screen?

How to deal with a Murder Hobo Paladin?

Why is there paternal, for fatherly, fraternal, for brotherly, but no similar word for sons?

Way to see all encrypted fields in Salesforce?

Why do we need a bootloader separate from our application program in microcontrollers?

Will Jimmy fall off his platform?



Animate/translate view from position of other view


How to transform a FAB into a popup menu?Stop EditText from gaining focus at Activity startupView still there but not visible after being moved out by animationAndroid: Expand/collapse animationHow to scale View / ViewGroup - animate layout in a proper way?Android - Control animation of viewflipper with finger/touch?How do I animate constraint changes?Animating views beyond parent container androidView.setClipBounds() does not limit the View animation area?Android Animations - Animate view to a specific positionAnimate/Translate the View from behind another View






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a fab and a framelayout which can host a fragment.



I'm trying to do a translation animation so that my framelayout starts at the position of the fab and ends up at its original position. (complex layout, the fab is in another xml file but <include> in same layout as the frame) So basically step 2 here: How to transform a FAB into a popup menu?



I have tried:



<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="340"
android:fromYDelta="431"
android:toXDelta="0"
android:toYDelta="0"
android:duration="1000"
android:fillAfter="true" />


and



val anim = TranslateAnimation(340f, 0f, 431f, 0f)


with



 myFab.setOnClickListener 
val frame = my_frame_im_about_to_fill_with_a_fragment
frame.startAnimation(anim)



So I tried with the values I get from these methods



myFab.getLocationOnScreen()
myFab.getLocationInWindow()


Both methods give (891, 1130). I've tried plugging those in or converting it to dp, that gets it closer(not very close still though).



Another strange thing is that I thought if I used absolute values in the animation I thought zero would be top left of the screen but it isn't. x: 0 y: 0 give me the same results as 0%,0% and 0%p,0%p. they all animate the view to the top left point of where the framelayout is in constrained to in the xml



How do I translate a view from another view to 'itself'?










share|improve this question






























    1















    I have a fab and a framelayout which can host a fragment.



    I'm trying to do a translation animation so that my framelayout starts at the position of the fab and ends up at its original position. (complex layout, the fab is in another xml file but <include> in same layout as the frame) So basically step 2 here: How to transform a FAB into a popup menu?



    I have tried:



    <translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="340"
    android:fromYDelta="431"
    android:toXDelta="0"
    android:toYDelta="0"
    android:duration="1000"
    android:fillAfter="true" />


    and



    val anim = TranslateAnimation(340f, 0f, 431f, 0f)


    with



     myFab.setOnClickListener 
    val frame = my_frame_im_about_to_fill_with_a_fragment
    frame.startAnimation(anim)



    So I tried with the values I get from these methods



    myFab.getLocationOnScreen()
    myFab.getLocationInWindow()


    Both methods give (891, 1130). I've tried plugging those in or converting it to dp, that gets it closer(not very close still though).



    Another strange thing is that I thought if I used absolute values in the animation I thought zero would be top left of the screen but it isn't. x: 0 y: 0 give me the same results as 0%,0% and 0%p,0%p. they all animate the view to the top left point of where the framelayout is in constrained to in the xml



    How do I translate a view from another view to 'itself'?










    share|improve this question


























      1












      1








      1








      I have a fab and a framelayout which can host a fragment.



      I'm trying to do a translation animation so that my framelayout starts at the position of the fab and ends up at its original position. (complex layout, the fab is in another xml file but <include> in same layout as the frame) So basically step 2 here: How to transform a FAB into a popup menu?



      I have tried:



      <translate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromXDelta="340"
      android:fromYDelta="431"
      android:toXDelta="0"
      android:toYDelta="0"
      android:duration="1000"
      android:fillAfter="true" />


      and



      val anim = TranslateAnimation(340f, 0f, 431f, 0f)


      with



       myFab.setOnClickListener 
      val frame = my_frame_im_about_to_fill_with_a_fragment
      frame.startAnimation(anim)



      So I tried with the values I get from these methods



      myFab.getLocationOnScreen()
      myFab.getLocationInWindow()


      Both methods give (891, 1130). I've tried plugging those in or converting it to dp, that gets it closer(not very close still though).



      Another strange thing is that I thought if I used absolute values in the animation I thought zero would be top left of the screen but it isn't. x: 0 y: 0 give me the same results as 0%,0% and 0%p,0%p. they all animate the view to the top left point of where the framelayout is in constrained to in the xml



      How do I translate a view from another view to 'itself'?










      share|improve this question
















      I have a fab and a framelayout which can host a fragment.



      I'm trying to do a translation animation so that my framelayout starts at the position of the fab and ends up at its original position. (complex layout, the fab is in another xml file but <include> in same layout as the frame) So basically step 2 here: How to transform a FAB into a popup menu?



      I have tried:



      <translate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromXDelta="340"
      android:fromYDelta="431"
      android:toXDelta="0"
      android:toYDelta="0"
      android:duration="1000"
      android:fillAfter="true" />


      and



      val anim = TranslateAnimation(340f, 0f, 431f, 0f)


      with



       myFab.setOnClickListener 
      val frame = my_frame_im_about_to_fill_with_a_fragment
      frame.startAnimation(anim)



      So I tried with the values I get from these methods



      myFab.getLocationOnScreen()
      myFab.getLocationInWindow()


      Both methods give (891, 1130). I've tried plugging those in or converting it to dp, that gets it closer(not very close still though).



      Another strange thing is that I thought if I used absolute values in the animation I thought zero would be top left of the screen but it isn't. x: 0 y: 0 give me the same results as 0%,0% and 0%p,0%p. they all animate the view to the top left point of where the framelayout is in constrained to in the xml



      How do I translate a view from another view to 'itself'?







      android animation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 8:11







      Adam

















      asked Mar 25 at 20:01









      AdamAdam

      1,3662 gold badges14 silver badges25 bronze badges




      1,3662 gold badges14 silver badges25 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Use ConstraintLayout for your layout, put your view constraints to starting position (here I will animate @+id/view after clicking @+id/fab. Animated view has to be VISIBLE or INVISIBLE - GONE will mess up animation.



           <androidx.constraintlayout.widget.ConstraintLayout
          /*constraint stuff*/>
          <View
          android:id="@+id/view"
          android:layout_width="120dp"
          android:layout_height="120dp"
          android:visibility="invisible"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintBottom_toBottomOf="parent" />

          <com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="120dp"
          app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
          app:layout_constraintEnd_toEndOf="@+id/symbolList" />

          </androidx.constraintlayout.widget.ConstraintLayout>


          There are few options:



          1. Use ObjectAnimator

          In your xml file put View that will be animated on fab position:



          view = findViewById(R.id.view)
          fab = findViewById(R.id.fab)

          fab.setOnClickListener

          view.visibility = View.VISIBLE
          val propertyX = PropertyValuesHolder.ofFloat(View.X, 0f)
          val propertyY = PropertyValuesHolder.ofFloat(View.Y, 0f)
          ObjectAnimator.ofPropertyValuesHolder(view, propertyX, propertyY).apply
          duration = 2000L
          start()





          1. Or use ViewPropertyAnimator (same XML as above)



             fab.setOnClickListener 
            view.animate()
            .x(0f)
            .y(0f)
            .setDuration(2000L)
            .start()




          2. Or use TransitionManager, MotionLayout, scene api or animate ConstraintSet manually.



            private fun startAnimation() 

            val animationEndConstraints = ConstraintSet().apply
            clone(container)
            clear(button.id, ConstraintSet.START)
            clear(button.id, ConstraintSet.TOP)
            // instead of parent you can use fab.id
            connect(button.id, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 0)
            connect(button.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0)

            TransitionManager.beginDelayedTransition(container)
            animationEndConstraints.applyTo(container)



          This approach will allow to specify start state as xml layout and end state as xml layout, but you will have less control.



          With other view position:



           fab.setOnClickListener 
          view.animate()
          .x(fab.left.toFloat())
          .y(fab.top.toFloat())
          .setDuration(2000L)
          .start()






          share|improve this answer

























          • Hmm havn't tried yet, but I don't get your xml setup? It can probably be cleaned up to give a clearer answer

            – Adam
            Mar 27 at 13:32











          • Just place view to be animated on starting position in your layout and animate to destination.

            – 3mpty
            Mar 28 at 9:58











          • is 0f, 0f the destination in your code?

            – Adam
            Mar 28 at 10:33











          • Yes, it will be top left corner.

            – 3mpty
            Mar 28 at 14:44











          • Hmm ok then its a problem. I want the animation to go from one point to another, neither of which is top left corner of the screen. In my example (0,0) was the origin/anchor of my view (your solution involve moving the view to the FAB so then moving to 0,0 doesn't make sense and the view needs to move to some coordinate/anchor view where I'd want it to go... but then again... that is my problem, those coordinates does not seem to be correct)

            – Adam
            Mar 28 at 15:09










          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',
          autoActivateHeartbeat: false,
          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%2f55345561%2fanimate-translate-view-from-position-of-other-view%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Use ConstraintLayout for your layout, put your view constraints to starting position (here I will animate @+id/view after clicking @+id/fab. Animated view has to be VISIBLE or INVISIBLE - GONE will mess up animation.



           <androidx.constraintlayout.widget.ConstraintLayout
          /*constraint stuff*/>
          <View
          android:id="@+id/view"
          android:layout_width="120dp"
          android:layout_height="120dp"
          android:visibility="invisible"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintBottom_toBottomOf="parent" />

          <com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="120dp"
          app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
          app:layout_constraintEnd_toEndOf="@+id/symbolList" />

          </androidx.constraintlayout.widget.ConstraintLayout>


          There are few options:



          1. Use ObjectAnimator

          In your xml file put View that will be animated on fab position:



          view = findViewById(R.id.view)
          fab = findViewById(R.id.fab)

          fab.setOnClickListener

          view.visibility = View.VISIBLE
          val propertyX = PropertyValuesHolder.ofFloat(View.X, 0f)
          val propertyY = PropertyValuesHolder.ofFloat(View.Y, 0f)
          ObjectAnimator.ofPropertyValuesHolder(view, propertyX, propertyY).apply
          duration = 2000L
          start()





          1. Or use ViewPropertyAnimator (same XML as above)



             fab.setOnClickListener 
            view.animate()
            .x(0f)
            .y(0f)
            .setDuration(2000L)
            .start()




          2. Or use TransitionManager, MotionLayout, scene api or animate ConstraintSet manually.



            private fun startAnimation() 

            val animationEndConstraints = ConstraintSet().apply
            clone(container)
            clear(button.id, ConstraintSet.START)
            clear(button.id, ConstraintSet.TOP)
            // instead of parent you can use fab.id
            connect(button.id, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 0)
            connect(button.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0)

            TransitionManager.beginDelayedTransition(container)
            animationEndConstraints.applyTo(container)



          This approach will allow to specify start state as xml layout and end state as xml layout, but you will have less control.



          With other view position:



           fab.setOnClickListener 
          view.animate()
          .x(fab.left.toFloat())
          .y(fab.top.toFloat())
          .setDuration(2000L)
          .start()






          share|improve this answer

























          • Hmm havn't tried yet, but I don't get your xml setup? It can probably be cleaned up to give a clearer answer

            – Adam
            Mar 27 at 13:32











          • Just place view to be animated on starting position in your layout and animate to destination.

            – 3mpty
            Mar 28 at 9:58











          • is 0f, 0f the destination in your code?

            – Adam
            Mar 28 at 10:33











          • Yes, it will be top left corner.

            – 3mpty
            Mar 28 at 14:44











          • Hmm ok then its a problem. I want the animation to go from one point to another, neither of which is top left corner of the screen. In my example (0,0) was the origin/anchor of my view (your solution involve moving the view to the FAB so then moving to 0,0 doesn't make sense and the view needs to move to some coordinate/anchor view where I'd want it to go... but then again... that is my problem, those coordinates does not seem to be correct)

            – Adam
            Mar 28 at 15:09















          1














          Use ConstraintLayout for your layout, put your view constraints to starting position (here I will animate @+id/view after clicking @+id/fab. Animated view has to be VISIBLE or INVISIBLE - GONE will mess up animation.



           <androidx.constraintlayout.widget.ConstraintLayout
          /*constraint stuff*/>
          <View
          android:id="@+id/view"
          android:layout_width="120dp"
          android:layout_height="120dp"
          android:visibility="invisible"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintBottom_toBottomOf="parent" />

          <com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="120dp"
          app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
          app:layout_constraintEnd_toEndOf="@+id/symbolList" />

          </androidx.constraintlayout.widget.ConstraintLayout>


          There are few options:



          1. Use ObjectAnimator

          In your xml file put View that will be animated on fab position:



          view = findViewById(R.id.view)
          fab = findViewById(R.id.fab)

          fab.setOnClickListener

          view.visibility = View.VISIBLE
          val propertyX = PropertyValuesHolder.ofFloat(View.X, 0f)
          val propertyY = PropertyValuesHolder.ofFloat(View.Y, 0f)
          ObjectAnimator.ofPropertyValuesHolder(view, propertyX, propertyY).apply
          duration = 2000L
          start()





          1. Or use ViewPropertyAnimator (same XML as above)



             fab.setOnClickListener 
            view.animate()
            .x(0f)
            .y(0f)
            .setDuration(2000L)
            .start()




          2. Or use TransitionManager, MotionLayout, scene api or animate ConstraintSet manually.



            private fun startAnimation() 

            val animationEndConstraints = ConstraintSet().apply
            clone(container)
            clear(button.id, ConstraintSet.START)
            clear(button.id, ConstraintSet.TOP)
            // instead of parent you can use fab.id
            connect(button.id, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 0)
            connect(button.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0)

            TransitionManager.beginDelayedTransition(container)
            animationEndConstraints.applyTo(container)



          This approach will allow to specify start state as xml layout and end state as xml layout, but you will have less control.



          With other view position:



           fab.setOnClickListener 
          view.animate()
          .x(fab.left.toFloat())
          .y(fab.top.toFloat())
          .setDuration(2000L)
          .start()






          share|improve this answer

























          • Hmm havn't tried yet, but I don't get your xml setup? It can probably be cleaned up to give a clearer answer

            – Adam
            Mar 27 at 13:32











          • Just place view to be animated on starting position in your layout and animate to destination.

            – 3mpty
            Mar 28 at 9:58











          • is 0f, 0f the destination in your code?

            – Adam
            Mar 28 at 10:33











          • Yes, it will be top left corner.

            – 3mpty
            Mar 28 at 14:44











          • Hmm ok then its a problem. I want the animation to go from one point to another, neither of which is top left corner of the screen. In my example (0,0) was the origin/anchor of my view (your solution involve moving the view to the FAB so then moving to 0,0 doesn't make sense and the view needs to move to some coordinate/anchor view where I'd want it to go... but then again... that is my problem, those coordinates does not seem to be correct)

            – Adam
            Mar 28 at 15:09













          1












          1








          1







          Use ConstraintLayout for your layout, put your view constraints to starting position (here I will animate @+id/view after clicking @+id/fab. Animated view has to be VISIBLE or INVISIBLE - GONE will mess up animation.



           <androidx.constraintlayout.widget.ConstraintLayout
          /*constraint stuff*/>
          <View
          android:id="@+id/view"
          android:layout_width="120dp"
          android:layout_height="120dp"
          android:visibility="invisible"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintBottom_toBottomOf="parent" />

          <com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="120dp"
          app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
          app:layout_constraintEnd_toEndOf="@+id/symbolList" />

          </androidx.constraintlayout.widget.ConstraintLayout>


          There are few options:



          1. Use ObjectAnimator

          In your xml file put View that will be animated on fab position:



          view = findViewById(R.id.view)
          fab = findViewById(R.id.fab)

          fab.setOnClickListener

          view.visibility = View.VISIBLE
          val propertyX = PropertyValuesHolder.ofFloat(View.X, 0f)
          val propertyY = PropertyValuesHolder.ofFloat(View.Y, 0f)
          ObjectAnimator.ofPropertyValuesHolder(view, propertyX, propertyY).apply
          duration = 2000L
          start()





          1. Or use ViewPropertyAnimator (same XML as above)



             fab.setOnClickListener 
            view.animate()
            .x(0f)
            .y(0f)
            .setDuration(2000L)
            .start()




          2. Or use TransitionManager, MotionLayout, scene api or animate ConstraintSet manually.



            private fun startAnimation() 

            val animationEndConstraints = ConstraintSet().apply
            clone(container)
            clear(button.id, ConstraintSet.START)
            clear(button.id, ConstraintSet.TOP)
            // instead of parent you can use fab.id
            connect(button.id, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 0)
            connect(button.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0)

            TransitionManager.beginDelayedTransition(container)
            animationEndConstraints.applyTo(container)



          This approach will allow to specify start state as xml layout and end state as xml layout, but you will have less control.



          With other view position:



           fab.setOnClickListener 
          view.animate()
          .x(fab.left.toFloat())
          .y(fab.top.toFloat())
          .setDuration(2000L)
          .start()






          share|improve this answer















          Use ConstraintLayout for your layout, put your view constraints to starting position (here I will animate @+id/view after clicking @+id/fab. Animated view has to be VISIBLE or INVISIBLE - GONE will mess up animation.



           <androidx.constraintlayout.widget.ConstraintLayout
          /*constraint stuff*/>
          <View
          android:id="@+id/view"
          android:layout_width="120dp"
          android:layout_height="120dp"
          android:visibility="invisible"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintBottom_toBottomOf="parent" />

          <com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="120dp"
          app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
          app:layout_constraintEnd_toEndOf="@+id/symbolList" />

          </androidx.constraintlayout.widget.ConstraintLayout>


          There are few options:



          1. Use ObjectAnimator

          In your xml file put View that will be animated on fab position:



          view = findViewById(R.id.view)
          fab = findViewById(R.id.fab)

          fab.setOnClickListener

          view.visibility = View.VISIBLE
          val propertyX = PropertyValuesHolder.ofFloat(View.X, 0f)
          val propertyY = PropertyValuesHolder.ofFloat(View.Y, 0f)
          ObjectAnimator.ofPropertyValuesHolder(view, propertyX, propertyY).apply
          duration = 2000L
          start()





          1. Or use ViewPropertyAnimator (same XML as above)



             fab.setOnClickListener 
            view.animate()
            .x(0f)
            .y(0f)
            .setDuration(2000L)
            .start()




          2. Or use TransitionManager, MotionLayout, scene api or animate ConstraintSet manually.



            private fun startAnimation() 

            val animationEndConstraints = ConstraintSet().apply
            clone(container)
            clear(button.id, ConstraintSet.START)
            clear(button.id, ConstraintSet.TOP)
            // instead of parent you can use fab.id
            connect(button.id, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 0)
            connect(button.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0)

            TransitionManager.beginDelayedTransition(container)
            animationEndConstraints.applyTo(container)



          This approach will allow to specify start state as xml layout and end state as xml layout, but you will have less control.



          With other view position:



           fab.setOnClickListener 
          view.animate()
          .x(fab.left.toFloat())
          .y(fab.top.toFloat())
          .setDuration(2000L)
          .start()







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 29 at 11:50

























          answered Mar 26 at 9:44









          3mpty3mpty

          9855 silver badges13 bronze badges




          9855 silver badges13 bronze badges












          • Hmm havn't tried yet, but I don't get your xml setup? It can probably be cleaned up to give a clearer answer

            – Adam
            Mar 27 at 13:32











          • Just place view to be animated on starting position in your layout and animate to destination.

            – 3mpty
            Mar 28 at 9:58











          • is 0f, 0f the destination in your code?

            – Adam
            Mar 28 at 10:33











          • Yes, it will be top left corner.

            – 3mpty
            Mar 28 at 14:44











          • Hmm ok then its a problem. I want the animation to go from one point to another, neither of which is top left corner of the screen. In my example (0,0) was the origin/anchor of my view (your solution involve moving the view to the FAB so then moving to 0,0 doesn't make sense and the view needs to move to some coordinate/anchor view where I'd want it to go... but then again... that is my problem, those coordinates does not seem to be correct)

            – Adam
            Mar 28 at 15:09

















          • Hmm havn't tried yet, but I don't get your xml setup? It can probably be cleaned up to give a clearer answer

            – Adam
            Mar 27 at 13:32











          • Just place view to be animated on starting position in your layout and animate to destination.

            – 3mpty
            Mar 28 at 9:58











          • is 0f, 0f the destination in your code?

            – Adam
            Mar 28 at 10:33











          • Yes, it will be top left corner.

            – 3mpty
            Mar 28 at 14:44











          • Hmm ok then its a problem. I want the animation to go from one point to another, neither of which is top left corner of the screen. In my example (0,0) was the origin/anchor of my view (your solution involve moving the view to the FAB so then moving to 0,0 doesn't make sense and the view needs to move to some coordinate/anchor view where I'd want it to go... but then again... that is my problem, those coordinates does not seem to be correct)

            – Adam
            Mar 28 at 15:09
















          Hmm havn't tried yet, but I don't get your xml setup? It can probably be cleaned up to give a clearer answer

          – Adam
          Mar 27 at 13:32





          Hmm havn't tried yet, but I don't get your xml setup? It can probably be cleaned up to give a clearer answer

          – Adam
          Mar 27 at 13:32













          Just place view to be animated on starting position in your layout and animate to destination.

          – 3mpty
          Mar 28 at 9:58





          Just place view to be animated on starting position in your layout and animate to destination.

          – 3mpty
          Mar 28 at 9:58













          is 0f, 0f the destination in your code?

          – Adam
          Mar 28 at 10:33





          is 0f, 0f the destination in your code?

          – Adam
          Mar 28 at 10:33













          Yes, it will be top left corner.

          – 3mpty
          Mar 28 at 14:44





          Yes, it will be top left corner.

          – 3mpty
          Mar 28 at 14:44













          Hmm ok then its a problem. I want the animation to go from one point to another, neither of which is top left corner of the screen. In my example (0,0) was the origin/anchor of my view (your solution involve moving the view to the FAB so then moving to 0,0 doesn't make sense and the view needs to move to some coordinate/anchor view where I'd want it to go... but then again... that is my problem, those coordinates does not seem to be correct)

          – Adam
          Mar 28 at 15:09





          Hmm ok then its a problem. I want the animation to go from one point to another, neither of which is top left corner of the screen. In my example (0,0) was the origin/anchor of my view (your solution involve moving the view to the FAB so then moving to 0,0 doesn't make sense and the view needs to move to some coordinate/anchor view where I'd want it to go... but then again... that is my problem, those coordinates does not seem to be correct)

          – Adam
          Mar 28 at 15:09








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345561%2fanimate-translate-view-from-position-of-other-view%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현