Background image and image view in Navigation Drawer

前端 未结 3 488
逝去的感伤
逝去的感伤 2021-01-07 00:11

I am trying out a navigation drawer design similar to play store App: I have got the menu part things working fine but I would like to add the profile image and user id in t

相关标签:
3条回答
  • 2021-01-07 00:41

    UPDATE:

    Take a look at this project for everything related with the drawer. https://github.com/Sottti/MaterialDesignNavDrawer

    OLD ANSWER:

    Take a look at my xml here: https://github.com/Sottti/BuyIt/blob/master/BuyIt/src/main/res/layout/activity_main.xml

    Pay attention at where it says "YOUR DRAWER".

    The Navigation Drawer is the second child in android.support.v4.widget.DrawerLayout.

    The second child is a LinearLayout containing a RelativeLayout and a ListView.

    The ListView is the Drawer list view it self.

    The Relative layout is the place where the image header is located.

    Try that, it's working for me.

    Luck!!

    0 讨论(0)
  • 2021-01-07 00:50

    Use the addHeaderView() method provided by ListView. Note: this will cause the ArrayAdapter to interpret the image as the first item in your list. To deal with this, use the option in addHeaderView to disable clicking, and move all the elements in your array up by 1 (essentially creating a dummy value at the 0th element). When your navigation drawer is first called, you may need to add a snippet like the following:

    if (savedInstanceState == null) {
                selectItem(1);
            }
    
    0 讨论(0)
  • 2021-01-07 00:58

    You can find how Google handle this issue in navdrawer_content layout of Google IO's Android app.
    Short answer: they don't use ListView.

    0 讨论(0)
提交回复
热议问题