Android - How to implement a NavigationDrawer that is partially visible at all times?

我与影子孤独终老i 提交于 2019-11-28 01:35:46

问题


I would like to have a NavigationDrawer in my Android project that shows the ListView partially at all times, and the items are also clickable, but when the user drags the drawer full ListView appears.

Below image is what I'm trying to achieve:

First one is the "Normal view" where you can see the small icons. Second one is when the user slides the navigation drawer so that it opens. Third one is when back in the normal view the user clicks A and C, so that the icons change their colour.

Any recommendations how to do this?

Thanks for answering :)


回答1:


I came across this open source library, https://github.com/StevenRudenko/ActionsContentView. I haven't personally used it so can't say it will fit in your exact use case of having a drawer at right but it does has the drawer on the left. Even then you could start from there and should be able to build upon it to fit your use case.




回答2:


thanks for all the answers. Here is what I did to make it work:

I used overlapping fragments and animation like suggested. While onCreate I calculated manually the width for the map (screensize - the drawer size while collapsed) so that it doesn't stretch strangely while modifying the drawer size. I set the drawer inside a fragment and the fragment visible at all times. After that I implemented OnGestureListener and made a GestureDetector to my activity, and started listening to touch events from the Drawer:

drawer.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View view, MotionEvent e) {
            gestureDetector.onTouchEvent(e);
            return false;
        }
    });

and then onFling-method

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    if(velocityX < -250) {
         //animation for increasing the list width from 80 to 240
    } else if (velocityY > 250 ) {
         //animation for decreasing the list width from 240 to 80
    }
    return true;
    }



回答3:


I would recommend that you use two overlapping fragments for this scenario. You can look at http://developer.android.com/guide/practices/tablets-and-handsets.html and http://developer.android.com/guide/components/fragments.html for guides.

If you have any more specific queries let me know.



来源:https://stackoverflow.com/questions/18978248/android-how-to-implement-a-navigationdrawer-that-is-partially-visible-at-all-t

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