尝试将卡片翻转动画实现为片段(Android)

时间:2013-12-06 06:28:54

标签: android android-fragments android-animation

我正在尝试为我的片段实现卡片翻转动画,我正在开发者网站上跟踪教程http://developer.android.com/training/animation/cardflip.html

然而,我得到一个奇怪的错误,我从开发人员网站下载了示例应用程序,令我惊讶的工作正常,但当我在我的特定活动中替换代码时,它给了我一个错误:

FragmentTransaction类型中的方法setCustomAnimations(int,int)不适用于参数(int,int,int,int)

以下是问题代码:

private View.OnClickListener on = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();  
            FragmentTransaction fragmentTransaction = fragmentManager  
                    .beginTransaction();

            fragmentTransaction.setCustomAnimations(
                            R.animator.card_flip_right_in, R.animator.card_flip_right_out,
                            R.animator.card_flip_left_in, R.animator.card_flip_left_out);
            //Fragment1_2 fragment1_2 = new Fragment1_2();  
            fragmentTransaction.replace(R.id.realtabcontent, new Fragment1_2()); 
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();  

        }
    };

修改 如果我评论setCustomAnimation的前两个或最后两个参数,一切都运行正常,但是我没有得到动画回复,我知道这是一个实现问题。下面是该片段的类文件的完整代码:

public class FragmentTab1 extends Fragment {
    MenuItem mMenuItem;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {


        View rootView = inflater.inflate(R.layout.fragmenttab1, container, false);
        ActionBar actionBar = getActivity().getActionBar();
        //  actionBar.setSubtitle("mytest");
        actionBar.setTitle("Reminders"); 
        setHasOptionsMenu(true);




        Button b = (Button)rootView.findViewById(R.id.button1); 
        b.setOnClickListener(on);
        b.setText("Check");
        return rootView;
    }
    private View.OnClickListener on = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();  
            FragmentTransaction fragmentTransaction = fragmentManager  
                    .beginTransaction();

            fragmentTransaction.setCustomAnimations(
                          //  R.animator.card_flip_right_in, R.animator.card_flip_right_out);
                            R.animator.card_flip_left_in, R.animator.card_flip_left_out);
            //Fragment1_2 fragment1_2 = new Fragment1_2();  
            fragmentTransaction.replace(R.id.realtabcontent, new Fragment1_2()); 
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();  

        }
    };

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater =getActivity().getMenuInflater();
        inflater.inflate(R.menu.main, menu);

        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {

        mMenuItem = item; 
        FragmentManager fragmentManager = getFragmentManager();  
        FragmentTransaction fragmentTransaction = fragmentManager  
                .beginTransaction();  
        switch (item.getItemId()) {
        case R.id.info:
            FragmentContact fragmentcontact = new FragmentContact(); 
            fragmentTransaction.replace(R.id.realtabcontent, fragmentcontact, "Fragment1_2");  
            mMenuItem.setEnabled(false); 
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();  
            break;

        default:

            break; 
        }

        return true;
    } 

    @Override
    public void onStart(){
        ActionBar actionBar = getActivity().getActionBar(); 
        actionBar.setTitle("Reminders"); 
        FragmentManager Fm = getFragmentManager();
        Fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); 
        super.onStart(); 
    }
    @Override
    public void onResume(){
        ActionBar actionBar = getActivity().getActionBar(); 
        actionBar.setTitle("Reminders"); 
        FragmentManager Fm = getFragmentManager();
        Fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); 
        super.onResume(); 
    }
}

任何我出错的提示都会受到极大的尊重!

0 个答案:

没有答案