Left to right and right to left android sliding panel

◇◆丶佛笑我妖孽 提交于 2020-01-05 10:32:35

问题


I saw a couple libraries that can do this, but i would like to avoid them if possible. I managed to do left to right, but i couldn't find out how to do on both directions. so here is my code:

    final SlidingPaneLayout slidingPaneLayout = SlidingPaneLayout.class.cast(root.findViewById(R.id.slidingpanelayout));
    slidingPaneLayout.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() {

        @Override
        public void onPanelSlide(View view, float v) {
        }

        @Override
        public void onPanelOpened(View view) {

            switch (view.getId()) {
                case R.id.fragment_secondpane:
                    getSupportFragmentManager().findFragmentById(R.id.fragment_firstpane).setHasOptionsMenu(true);
                    getSupportFragmentManager().findFragmentById(R.id.fragment_secondpane).setHasOptionsMenu(false);
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onPanelClosed(View view) {

            switch (view.getId()) {
                case R.id.fragment_secondpane:
                    getSupportFragmentManager().findFragmentById(R.id.fragment_firstpane).setHasOptionsMenu(false);
                    getSupportFragmentManager().findFragmentById(R.id.fragment_secondpane).setHasOptionsMenu(true);
                    break;
                default:
                    break;
            }
        }
    });

is there a way to make sliding panels on both left to right and right to left directions so that i will have 3 fragments, without any libraries?


回答1:


Your solution lies in ViewPager. Here are a couple of links for tutorial.

Detailed Tutorial with source code and xml files

Vogella Tutorial for ViewPage


UPDATE

What you are asking about is Navigation Drawer. You can find tons of tutorial on internet. Here are some good ones.

Android Official Tutorial

Detailed tutorial for Beginers

Hope this helps



来源:https://stackoverflow.com/questions/18655357/left-to-right-and-right-to-left-android-sliding-panel

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