Yalantis / Side-Menu.Android

Side menu with some categories to choose.
https://yalantis.com
Apache License 2.0
5.24k stars 1.51k forks source link

Can`t use more than two fragment ? #14

Closed Null-Ouwenjie closed 9 years ago

Null-Ouwenjie commented 9 years ago

Because
viewAnimator = new ViewAnimator<>(this, menuItemList, contentFragment, drawerLayout, this);
so,if I replace OtherFragment,
The screenShotable in
findViewById(R.id.content_overlay).setBackgroundDrawable(new BitmapDrawable(getResources(), screenShotable.getBitmap()));

The content_overlay can`t change to new fragment's Bitmap,It lead to switch animation are ugly.

Sorry,Maybe My English is so bad = =#

Apisov commented 9 years ago

Can you please provide more details? Code, screenshots, videos, etc. If I correctly anderstand you, than we don't have limit on amount of fragments in use. Because in method onSwitch we create new fragment each time.

Null-Ouwenjie commented 9 years ago

Thank you for your reply I try to use English to describe the problem clearly T.T

In My project,I want to use Side-Menu to Jump to the different Fragment. example OneFragment , TwoFragment , ThreeFragment ... when I open this APP will display OneFragment so , in the MainActivity ,I write onCreate() method like :

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

    if(savedInstanceState == null) {
        oneFragment = OneFragment.newInstance();
        getSupportFragmentManager().beginTransaction().add(R.id.content_frame, oneFragment ).commit();
    }
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerLayout.setScrimColor(Color.TRANSPARENT);
    leftlayout = (LinearLayout) findViewById(R.id.left_drawer);
    leftlayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.closeDrawers();
        }
    });

    setToolBar();
    createMenuList();

    viewAnimator = new ViewAnimator<>(this, menuItemList, oneFragment , drawerLayout, this);

}   

when i click other MenuItem
I write the replaceFragment method like this:

private ScreenShotable replaceFragment(Resourceble slideMenuItem,ScreenShotable screenShotable, int topPosition) { View view = findViewById(R.id.content_frame); int finalRadius = Math.max(view.getWidth(), view.getHeight()); SupportAnimator animator = ViewAnimationUtils.createCircularReveal(view, 0, topPosition, 0, finalRadius); animator.setInterpolator(new AccelerateInterpolator()); animator.setDuration(ViewAnimator.CIRCULAR_REVEAL_ANIMATION_DURATION);

    findViewById(R.id.content_overlay).setBackgroundDrawable(new BitmapDrawable(getResources(), screenShotable.getBitmap()));
    animator.start();

    switch (slideMenuItem.getName()){
        case ONE:
            OneFragment oneFragment = OneFragment .newInstance();
            getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, oneFragment ).commit();
            break;
        case TWO:
            TwoFragment twoFragment = TwoFragment .newInstance();
            getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, twoFragment ).commit();
            break;
        case THREE:
            ThreeFragment threeFragment = ThreeFragment .newInstance();
            getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, threeFragment ).commit();
            break;
        case ABOUT:
            AboutFragment aboutFragment = AboutFragment.newInstance();
            getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, aboutFragment).commit();
            break;
        default:
            break;

    }
    return oneFragment;
}   

In order to describe, I changed my code, As written above.

_my problem is _ When I switch to another Fragment the oneFragment is always appear

example In the twofragment jump to threefragment At the beginning,the twofragment is Immediately disappear,then It will appear onefragment ,then appear animation to display threefragment

so I guess is the
viewAnimator = new ViewAnimator<>(this, menuItemList, oneFragment, drawerLayout, this);
cause this problem ? because it construction method is passed a oneFragment...

Don't know if I use the right way Thank you again for your attention

Null-Ouwenjie commented 9 years ago

Long time no see my code today I found the BUG in the code To solve the problem before


The cause of my problem is in addition to oneFragment ,another Fragment was not implement ScreenShotable !

It's my carelessness

Apisov commented 9 years ago

Sorry that we didn't help you directly. But anyway it's great that you figured out what was a problem by yourself :)

mohamedebrahim96 commented 7 years ago

Null-Ouwenjie can you share all the code,please ??

Null-Ouwenjie commented 7 years ago

@mohamedebrahim96 The code in this project : https://github.com/Null-Ouwenjie/Jide-Note this project has been for a long time without maintenance.

mohamedebrahim96 commented 7 years ago

ya thanks Null-Ouwenjie for sharing the code ... i hope you can solve this problem with me ? https://github.com/Yalantis/Side-Menu.Android/issues/71