Android Navigationview Analytics

Source: Internet
Author: User

Recently in the study of the Sideslip menu found some problems, if you have not contacted before will certainly go to Baidu, and I have seen a lot of demo, I believe you see examples are the following layout of the

Headerlayout Load header layout, menu loading menus, so that the composition of a complete menu, then the problem, menu click events posted online, very simple, then the head? You may not be able to start, then only look at the source code, Navigationview in the Inflateheaderview this method, see this method you will certainly feel that is through this method load head layout, well, now the method has, But when you load this method, you'll notice that there are two header layouts in the menu, is obviously loaded two times, the first time is in the layout file specified in the Headerlayout, when you slide the menu will load the header layout, the second time you are in the code again loaded. So there are two layouts. Just delete the headerlayout line of code in the layout to achieve the effect you want. The code to bind the header layout is given below


Layout file
<android.support.design.widget.nacigationview
Android:layout_width= "Wrap_content"
android:layout_height= "Match_parent"
Andriod:layout_gravity= "Start"
app:headerlayout= "@layout/drawer_header"
app:menu= "@menu/drawer"/>

Bound sideslip Menu Headerlayout layout,

View Drawview = Nav_view.inflateheaderview (R.layout.view_leftmenu);
ImageView user_pic = (imageview) Drawview.findviewbyid (r.id.imag_user_pic);
The problem can be resolved by Navigationview to load the header layout and then control binding.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.