Open source China Oschina Android Client Source Analysis (2) Sliding menu

Source: Internet
Author: User

1 Sliding menu Oschina Use the Android.support.v4.widget.DrawerLayout, previously did not use this control, Baidu, under the general understanding of the following:

1.1 similar to LinearLayout, is a layout control.

1.2 when used, it has two parts, the main content view and the menu content view, and the main content must be placed in front of the menu content, in order to let Drawerlayout identify who is the part of the menu, its width and height need to be set to Match_parent. What is the main content section here? In fact, the main interface to display the various fragment and the bottom of the navigation section, so Oschina in the main interface layout file directly using the control as the outermost control.

1.3 Drawerlayout use must be on top of API11, and the API for all apps is minsdkversion 11.

Layout file Fragment_navigation_drawer.xml, the layout of the whole two parts: Can be dragged Net.oschina.app.widget.CustomerScrollView, the interior contains the specific menu item Fragment_navigation_drawer_ The Items.xml layout file and the Fragment_navigation_drawer_foot.xml layout file at the bottom of the menu for setting and closing functions.

From the analysis of the layout file, we should apply the following points:

1<net.oschina.app.widget.customerscrollview A combination of android:layout_height= "0dip" plus android:layout_weight= "1" was used, about the usage of android:layout_weight, The key is to display proportionally in the linearlayout. But <include layout= "@layout/fragment_navigation_drawer_foot"/> does not have the same settings android:layout_weight properties, Does this make the menu item part completely occupy the entire area? Tracing to Fragment_navigation_drawer.xml, it was found that the property was set at the bottom of the parent layout file, plus the outermost linearlayout vertical layout. , Oh, after the menu item, the bottom is forced at the bottom, which results in the final effect: the menu item part occupies all areas except the bottom control.

2<include> General two functions: If the layout file has a public part, then can be extracted out of the public, another point, good programming habits: modular, readable and so on. The Oschina client should be the region of the latter.

3 in the menu item layout file, the same style is set and referenced because the four parts are wide, high, background, click Effect, etc., which reduces the redundancy of the code.

<style name= "Menuitemlayoutstyle" >

<item name= "Android:layout_width" >match_parent</item>

<item name= "Android:layout_height" >wrap_content</item>

<item name= "Android:minheight" >55dip</item>

<item name= "Android:gravity" >center_vertical</item>

<item name= "Android:orientation" >horizontal</item>

<item name= "Android:paddingleft" >15dip</item>

<item name= "Android:paddingright" >15dip</item>

<item name= "Android:background" > @drawable/drawer_menu_item_background</item></style>

4 refer to Android.support.v4.widget.DrawerLayout's related blog http://www.cnblogs.com/mengdd/p/3213378.html

5 recommended another blog to implement the sliding menu: http://blog.csdn.net/lmj623565791/article/details/36677279


Open source China Oschina Android Client Source Analysis (2) Sliding menu

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.