Creating a slower transition. TransitionManager.beginDelayedTransition(); is too fast

夙愿已清 提交于 2020-01-02 01:15:29

问题


I am creating a transition. And when a button is clicked the following method is executed. The method changed the size , position of the image view, and it fades it out. I am using TransitionManager.beginDelayedTransition(); is too fast. to slow down the transition.. but it is still going too fast. What can i do to slow down the transition. Thank You.

private void moveIcon() {
    View moveableIcon = findViewById(R.id.moveableImageView);

    TransitionManager.beginDelayedTransition(myLayout);

    // change the position of the icon

    RelativeLayout.LayoutParams positionRule = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT ,

            RelativeLayout.LayoutParams.WRAP_CONTENT);
    positionRule.addRule(RelativeLayout.ALIGN_PARENT_TOP , RelativeLayout.TRUE);

    positionRule.addRule(RelativeLayout.ALIGN_PARENT_LEFT , RelativeLayout.TRUE);

    moveableIcon.setLayoutParams(positionRule);

    // change the size of the button

    ViewGroup.LayoutParams sizeRules = moveableIcon.getLayoutParams();
    sizeRules.width = 50;
    sizeRules.height = 50;
    moveableIcon.setLayoutParams(sizeRules);

    fadeOutAndHideImage(image);
}

private void fadeOutAndHideImage(final ImageView img)
{
    Animation fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setInterpolator(new AccelerateInterpolator());
    fadeOut.setDuration(1000);

    fadeOut.setAnimationListener(new Animation.AnimationListener()
    {
        public void onAnimationEnd(Animation animation)
        {
            img.setVisibility(View.GONE);
        }
        public void onAnimationRepeat(Animation animation) {}
        public void onAnimationStart(Animation animation) {}
    });

    img.startAnimation(fadeOut);
}

回答1:


Try to use this method: beginDelayedTransition(android.view.ViewGroup, android.transition.Transition)

AutoTransition autoTransition = new AutoTransition();
autoTransition.setDuration(3000);

TransitionManager.beginDelayedTransition(myLayout, autoTransition);



回答2:


Instead of using TransitionManager.beginDelayedTransition(myLayout); use TransitionManager.go().

The Transition that is most probably used by TransitionManager.beginDelayedTransition(myLayout); is ChangeBounds. You can set the duration of this ChangeBounds transition easily enough and then tell the TransitionManager to run it:

private void moveIcon() {
    View moveableIcon = findViewById(R.id.moveableImageView);

    // change the position of the icon 

    RelativeLayout.LayoutParams positionRule = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT ,

            RelativeLayout.LayoutParams.WRAP_CONTENT);
    positionRule.addRule(RelativeLayout.ALIGN_PARENT_TOP , RelativeLayout.TRUE);

    positionRule.addRule(RelativeLayout.ALIGN_PARENT_LEFT , RelativeLayout.TRUE);

    moveableIcon.setLayoutParams(positionRule);

    // change the size of the button 

    ViewGroup.LayoutParams sizeRules = moveableIcon.getLayoutParams();
    sizeRules.width = 50;
    sizeRules.height = 50;
    moveableIcon.setLayoutParams(sizeRules);

    ChangeBounds myTransition = new ChangeBounds();
    myTransition.setDuration(1000L);
    TransitionManager.go(new Scene(myLayout), myTransition);

    fadeOutAndHideImage(image);
}

Hope this helps.



来源:https://stackoverflow.com/questions/29785425/creating-a-slower-transition-transitionmanager-begindelayedtransition-is-too

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!