android – 使用AnimatorSet在两个视图之间实现卡片翻转动画

前端之家收集整理的这篇文章主要介绍了android – 使用AnimatorSet在两个视图之间实现卡片翻转动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在制作一个汉字卡片应用程序.我希望有一个LinearLayout代表前面,另一个代表卡的背面,我已经在一个XML布局中声明了.
问题是,第二个LinearLayout总是不可见的,第一个正常动画.
无论如何在动画进行时进行方法调用?我想将第一个布局的可见性设置为GONE,将第二个布局的可见性设置为VISIBLE?

或者是否有另一种更好的方法来实现翻转卡?

以下是我的代码.预先感谢.

FlashcardsFragment.java

public class FlashcardsFragment extends Fragment
{
    private AnimatorSet showFrontAnim = new AnimatorSet();
    private AnimatorSet showBackAnim = new AnimatorSet();
    private boolean isShowingBack = false;

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
    {
        View v =  inflater.inflate(R.layout.fragment_flashcard,container,false);

        LinearLayout cardFront = (LinearLayout) v.findViewById(R.id.card_front_layout);
        LinearLayout cardBack = (LinearLayout) v.findViewById(R.id.card_back_layout);

        // Load the animator sets from XML and group them together

        AnimatorSet leftIn   = (AnimatorSet) AnimatorInflater
                .loadAnimator(getActivity(),R.animator.card_flip_left_in);
        AnimatorSet rightOut = (AnimatorSet) AnimatorInflater
                .loadAnimator(getActivity(),R.animator.card_flip_right_out);
        AnimatorSet leftOut  = (AnimatorSet) AnimatorInflater
                .loadAnimator(getActivity(),R.animator.card_flip_left_out);
        AnimatorSet rightIn  = (AnimatorSet) AnimatorInflater
                .loadAnimator(getActivity(),R.animator.card_flip_right_in);

        leftIn.setTarget(cardFront);
        rightOut.setTarget(cardBack);
        showFrontAnim.playTogether(leftIn,rightOut);

        leftOut.setTarget(cardFront);
        rightIn.setTarget(cardBack);
        showBackAnim.playTogether(leftOut,rightIn);

        LinearLayout cardContainer = (LinearLayout) 
                v.findViewById(R.id.card_container_layout);
        // Set the flip animation to be triggered on container clicking
        cardContainer.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (isShowingBack) {
                    showFrontAnim.start();
                    isShowingBack = false;
                }
                else {
                    showBackAnim.start();
                    isShowingBack = true;
                }
            }
        });

        return v;
    }
}
最佳答案
编辑:我的问题已经解决,我将容器布局更改为FrameLayout,这样两个视图可以相互重叠.感谢你所做的一切 :))
原文链接:https://www.f2er.com/android/431148.html

猜你在找的Android相关文章