在viewpager中的片段内的动画

时间:2013-01-22 16:12:38

标签: android animation android-fragments android-viewpager


我有一个问题。如上所述,我的ViewPager里面有5个片段。在最后一个片段中,我有两个相对布局,里面有一些小部件。在按钮上单击我有动画,将相对布局更改为可见。
我的问题是,当我向后滚动时,已经消失的视图全部可见......任何人都经历过类似的事情?

public class WelcomeActivity extends FragmentActivity{

    private FragmentAdapter adapter;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.welcome_activity);

        viewPager = (ViewPager) findViewById(R.id.pager);
        adapter = new FragmentAdapter(getSupportFragmentManager(), viewPager);
        viewPager.setAdapter(adapter);
}


public class FragmentAdapter extends FragmentPagerAdapter{

    private ViewPager pager;
    private Fragment mFragmentAtPos0;
    private FragmentManager mFragmentManager;

    public FragmentAdapter(FragmentManager fm, ViewPager p) {
        super(fm);
        this.pager = p;
        this.mFragmentManager = fm;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
        case 0:
            return new ScreenWelcome(pager, this);
        case 1:
            return new ScreenTutorial1();
        case 2:
            return new ScreenTutorial2();
        case 3:
            return new ScreenTutorial3();
        case 4:
            return new ScreenTutorial4();
        case 5:
            return new FlipAnimationFragment();
        default:
            return null;
        }
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public int getCount() {
        return 6;
    }


public class FlipAnimationFragment extends Fragment{
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.flip_animation, container, false);
        layout = (RelativeLayout) view.findViewById(R.id.layout);
        sign_up = (RelativeLayout) view.findViewById(R.id.relativeLayoutSignUp);
        log_in = (RelativeLayout) view.findViewById(R.id.relativeLayoutLogIn);

        create_account_page = (Button) view.findViewById(R.id.buttonCreateAccount);
        log_in_page = (Button) view.findViewById(R.id.buttonSignUpLogIn);

        log_in_page.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(!pressed){
                    pressed = true;

                    layout.startAnimation(flip);
                }

            }
        });
        create_account_page.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(!pressed){
                    pressed = true;

                    layout.startAnimation(flip);
                }

            }
        });
}
@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        flip = new FlipAnimator(sign_up, log_in, 240, 400);
}

0 个答案:

没有答案