Why does my android transition ignore the transitionlistener?

I'm trying to update the display before calling TransitionManager.beginDelayedTransition (viewGroup, new AutoTransition ()) to smooth the display. But I find that sometimes I will update the content quickly, and Android will be confused.

Therefore, I added a transitionlistener in autotransition, in which transitionend() calls back to indicate that the transition has been completed. At this time, I set the animation to the new state of the screen. However, I found that it is usually not even called

Is there a way to call back when a) the transformation ends or b) the transformation is never called first?

More information:

I'm using xamarin.android. I have a code that looks like this to start the conversion:

if (animated && viewGroup != null && Utils.Api19PlusKitkat) {
    App.Log("** Beginning animation.");
    var transition = new AutoTransition();
    transition.AddListener(new TransitionListener(this));
    TransitionManager.BeginDelayedTransition(viewGroup, transition);
}

Transitionlistener is simple:

public class TransitionListener : Java.Lang.Object, Transition.ITransitionListener {
    readonly TreeNode owner;

    public TransitionListener(TreeNode owner)
    {
        this.owner = owner;
    }

    public void Ontransitionend(Transition transition)
    {
        App.Log("**** TransitionListener: Transition End.");
        owner.FinishTransition();
    }

    public void OnTransitionCancel(Transition transition) {}
    public void OnTransitionPause(Transition transition) {}
    public void OnTransitionResume(Transition transition) {}
    public void OnTransitionStart(Transition transition) {
        App.Log("**** TransitionListener: Transition Start.");
    }
}

When I check the application log, I will see many cases of "start animation", but rarely "transition start" or "transition end" (at present, I don't see any examples, but sometimes I have seen it happen in the log)

resolvent:

Upd2:

I think I see now. After two days of fruitless attempts, I managed to solve the problem

Transitionmanager. Begindelayedtransition() triggers something only if there is something to update on the screen

For example, if you set setonclicklistener with transitionmanager. Begindelayedtransition() in onclick to a button with a custom background without a selector (Android: background = "#000", instead of the default selector), nothing will happen and the transition will not begin (as you can see). At the same time, If you assign the same onclicklistener to a default style button (that is, with a selector as the background) - the transition will begin immediately

Similarly, if you make some UI changes after calling transitionmanager. Begindelayedtransition():

public void changeScene(View v){
    AutoTransition autoTransition = new AutoTransition();
    autoTransition.setDuration(3000);
    autoTransition.addListener(new Transition.TransitionListener() {
        @Override
        public void onTransitionStart(Transition transition) {
            Toast.makeText(MainActivity.this, "start", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void ontransitionend(Transition transition) {
            Toast.makeText(MainActivity.this, "end", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onTransitionCancel(Transition transition) {}

        @Override
        public void onTransitionPause(Transition transition) {}

        @Override
        public void onTransitionResume(Transition transition) {}
    });

    TransitionManager.beginDelayedTransition(container, autoTransition);
    findViewById(R.id.btn1).setVisibility(
            (findViewById(R.id.btn1).getVisibility()) == View.VISIBLE?
                     View.INVISIBLE : View.VISIBLE);
}

This snippet will work because it should:

However, once the visibility setter is deleted, the transition is added to the to-do list of the transition manager and will not be executed (method name display - may be delayed). It will only be executed during the next UI change:

In this example, I removed setvisibility () - you can see the result: animation (in my case, just toasts) starts only after clicking the button with the selector as the background (i.e. UI changes occur)

Therefore, the solution would be - "make sure there are some UI changes after calling transitionmanager. Begindelayedtransition()"

I hope it will help you

PS, however, it's strange that transitionmanager. Go() written after transitionmanager. Begindelayedtransition() doesn't work properly. The only solution I've found here is to put it in ontransitionend for delayed conversion

Upd1:

I first thought that it might be related to xamarin. Then I found two examples of using begindelayedtransition in xamarin.android: xamarin / monodroid samples and garuma / moyeu. To check whether your problem is related to xamarin.android - I suggest debugging these two projects to see whether transition listener triggers transition events

Both examples use transitionmanager. Begindelayedtransition() with a parameter (ViewGroup). Checking the source code of transitionmanager shows that the 1 parameter method is calling begindelayedtransition (sceneroot, null);

public static void beginDelayedTransition(final ViewGroup sceneRoot) {
    beginDelayedTransition(sceneRoot, null);
}

Replace null with sdefaulttransition:

private static Transition sDefaultTransition = new AutoTransition();
....
public static void More ...beginDelayedTransition(final ViewGroup sceneRoot, Transition transition) {
    if (!sPendingTransitions.contains(sceneRoot) && sceneRoot.isLaidOut()) {
        if (Transition.DBG) {
            Log.d(LOG_TAG, "beginDelayedTransition: root, transition = " +
                    sceneRoot + ", " + transition);
        }
        sPendingTransitions.add(sceneRoot);
        if (transition == null) {
            transition = sDefaultTransition;
        }
        final Transition transitionClone = transition.clone();
        sceneChangeSetup(sceneRoot, transitionClone);
        Scene.setCurrentScene(sceneRoot, null);
        sceneChangeRunTransition(sceneRoot, transitionClone);
    }
}

Therefore, to debug it, you must get the default transactionmanager. Getdefaulttransition () and add it to it

If it works, then we'll have to look for problems in your code. If it doesn't work - good. Then, maybe we found a system error and can archive it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>