Development issue/problem:
I plan to implement something similar in one of my projects, but I don’t understand the concept, nor does such a tutorial exist, especially since you don’t see it very often. So it seems. Click here to go to the source.
Hardware animation (to move the button) and opening circle
(to give the impression that the button has exploded).
If you find a better answer to the following question, you can place it here.
How can I solve this problem?
Solution 1:
It’s an old question, but it’s still an interesting one. Here’s how I implemented it:
The first thing to do is to create two ViewGroups, which are called scenes in the api transition. The first scene contains views before the transition, the second scene contains views after the transition. Then simply replace the first scene with the second and make a transition that describes how the views of the first scene change into the second, as well as how the views of the first scene disappear and the views of the second scene appear.
In this example there is a problem with the Fab button, because this is the only image that is animated from the white part of the main screen of the scene. The scenes are therefore in full screen with an indentation at the top corresponding to the height of Monday’s blue title.
By default, all transitions are listed here, except those with a yellow background. The yellow background display
appears in the second scene with the circular aperture animation. And it disappears with a circular collapse animation. There’s no such animation by default, so I wrote mine:
import android.animation.animator;
import android.animation.AnimatorListenerAdapter;
import android.support.transition.steel;
import android.transition.visible;
import android.view.view;
import android.view.ViewAnimationUtils;
import android.view.viewGroup ;
public class CircularTranslation extends visibility {
@Public Animator
onAppear(ViewGroup sceneRoot, View View, TransitionValues startValues, TransitionValues endValues) {
int startRadius = 0;
int endRadius = (int) Math.hypot(view.getWidth(), view.getHeight());
Animator reveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startRadius, endRadius);
// Make the view invisible until the animation actually starts
view.setAlpha(0);
reveal.addListener(new AnimatorListenerAdapter() {
@Override
public blank atAnimationStart(Animator animation) {
view.setAlpha(1);
}
});
return reveals;
}
@Override
public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
int endRadius = 0 ;
int startRadius = (int) Math.hypot(view.getWidth(), view.getHeight()));
Animator reveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startRadius, endRadius);
return reveal;
}
}
The full code is here:
import android.os.bundle;import android.support.annotation.NonNull;import android.support.design.widget.floatingActionButton;import android.support.transition.ArcMotion;import android.transition.changeBounds.import android.support.transition.Fade;import android.transition.Scene.import android.support.scene;import android.support.transition.scene;import android.support.transition.slide;import android.support.transition.transition.transition.ListenerAdapter; import android.support.transitionManager; import android.support.transition.Fade; import android support.transition.Scene; import android support.transition.Scene; import android support.transitionSet; import android support.v7.app.App.AppCompatActivity; import android.view.Gravity; import android.view.view; import android.viewGroup;
The MainActivity public class expands AppCompatActivity {
closed ViewGroup mSceneRoot ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.active_main);
setSupportActionBar(findViewById(R.id.toolbar)));
mSceneRoot = findViewById(R.id.sceneRoot);
// show scene1 without animation
showScene1(false);
}
private void showScene1(boolean animation) {
ViewGroup root = (ViewGroup) getLayoutInflater().inflate(R.layout.scene1, null);
FloatingActionButton fab = root.findViewById(R.id.fab);
fab.setOnClickListener(v -> {
showScene2();
});
Scene scene = new Scene(mSceneRoot, root);
Transition = animated? getScene1Transition(): null;
TransitionManager.go(scene, transition);
}
private void showScene2() {
ViewGroup root = (ViewGroup) getLayoutInflater().inflate(R.layout.scene2, null);
View btnBack = root.findViewById(R.id.btnCancel);
btnBack.setOnClickListener(v -> {
showScene1(true);
})
Scene scene = new scene (mSceneRoot, root);
Transition = getScene2Transition();
TransitionManager.go(scene, transition);
}
private Transition getScene2Transition() {
TransitionSet set = new TransitionSet() ;
//fab changes PositionChangeBounds changeTransform = new ChangeBounds();changeTransform.addListener(new TransitionListenerAdapter() {@Overrider void onTransitionEnd(@NonNull Transition))) { //hide fab button at the end of animationmSceneRoot.findViewById(R.id.fab).setVisibility(View.INVISIBLE);}.}); changeTransform.addTarget(R.id.fab); changeTransform.setDuration(300); //fab arcMotion arcMotion = new ArcMotion(); arcMotion.setMaximumAngle(45); arcMotion.setMinimumHorizontalAngle(90); arcMotion.setMinimumVerticalAngle(0); changeTransform.setPathMotion(arcMotion); set.addTransition(changeTransform);
//bg cycle open animation
CircularRevealTransition crt = new CircularRevealTransition();
crt.addTarget(R.id.yellowBG);
crt.setStartDelay(200);
crt.setDuration(600);
set.addTransition(crt) ;
The // buttons appear
fade = new Fade();
fade.addTarget(R.id.btnBegin);
fade.addTarget(R.id.btnCancel);
fade.addTarget(R.id.text);
fade.setStartDelay(600);
set.addTransition(fade) ;
// buttons in the left column slide left
slide = new slide (Gravity.LEFT);
slide.addTarget (R.id.slideLeftContainer); set
.addTransition(slide); column
// buttons in the right column slide right
slide2 = new slide (Gravity.RIGHT);
slide2.addTarget(R.id.slideRightContainer);
set.addTransition(slide2);
return set;
}
private Transition getScene1Transition() {
TransitionSet set = new TransitionSet() ;
// Hide buttons in scene2
fade = new Fade();
fade.addTarget(R.id.btnBegin);
fade.addTarget(R.id.btnCancel);
fade.addTarget(R.id.btnCancel);
set.addTransition(fade) ;
// The circular collapse animation starts
CircularRevealTransition crt = new CircularRevealTransition();
crt.addTarget(R.id.yellowBG);
crt.setDuration(600);
set.addTransition(crt) ;
//
ChangeBounds changeTransform = new ChangeBounds();
changeTransform.addTarget(R.id.fab);
changeTransform.setDuration(300);
changeTransform.setStartDelay(500);
//arcPath
arcMotion arcMotion = new ArcMotion();
arcMotion.setMaximumAngle(45);
arcMotion.setMinimumHorizontalAngle(90);
arcMotion.setMinimumVerticalAngle(0);
changeTransform.setPathMotion(arcMotion);
set.addTransition(changeTransform) ;
//
slide = new slide (Gravity.LEFT);
slide.addTarget (R.id.slideLeftContainer);
slide.setStartDelay(500);
setTransition(slide) ;
// the column of the right button is placed on the right side
Slide2 = new Slide(Gravity.RIGHT);
slide2.addTarget(R.id.slideRightContainer);
slide2.setStartDelay(500);
set.addTransition(slide2);
return set;
}
}
activity_main.xml :
Scene 1.xml :
Scene 2.xml :
button.xml :
Values.xml :
Transition test
#3F51B5
#303F9F
#FF4081
16dp
200dp
132dp
Solution 2:
I think what you’re looking for makes sense.
On devices with pre-installed Lollipop this can be done with the ActivityOptionsCompatible wizard.
Some useful links that may help you:
Good luck!
Related Tags:
materialcontainertransform,android expand floating action button,floating animation android,android fab to full screen,custom fab icon android,extended floating action button,floating action button animation flutter,floating button with animation,animated fab button with more options,movable floating action button android,custom floating action button android,what is floating action button in whatsapp,android floating action button menu,floating action button android,pressedtranslationz,positioning floating action button,floating action button android github,floating action button ios,floating action button android example,add floating layout android,how to use floating action button in androidx,change floating action button color,android floating action button icon color,search floating action button,coordinatorlayout floatingactionbutton,layout anchor android,whatsapp floating button android,floating action button example in android,circular floating action menu android github,floating bubble animation android,android floating action button animation,movable floating action button android github,floating-button animation android github,android fab show/hide animation