Implementation principle and code of the menu bar at the bottom of Android imitation UC

Source: Internet
Author: User

Related Links:
Menu Bar implementation at the bottom of Android

After reading ViewPager recently, I just wanted to make such a Demo. Of course, I also referred to the grid menu in the examples of experts and started to use the custom imgBtn, however, we found that the layout is not good on the pager tab, so it is best to select the GridView, which is simple and practical.

1. Master interface xml
Activity_main.xmlCopy codeThe Code is as follows: <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: background = "@ drawable/bg"
Tools: context = ". MainActivity">
<Button
Android: id = "@ + id/btn_menu"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignParentTop = "true"
Android: layout_centerHorizontal = "true"
Android: text = "show/hide Menu"/>
<LinearLayout
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_below = "@ + id/btn_menu"
Android: gravity = "center"
Android: orientation = "horizontal">
<Com. example. myMenu. MyImgBtn
Android: id = "@ + id/main_btn1"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_margin = "15dp"
Android: layout_weight = "1"/>
<Com. example. myMenu. MyImgBtn
Android: id = "@ + id/main_btn2"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_margin = "15dp"
Android: layout_weight = "1"/>
<Com. example. myMenu. MyImgBtn
Android: id = "@ + id/main_btn3"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_margin = "15dp"
Android: layout_weight = "1"/>
<Com. example. myMenu. MyImgBtn
Android: id = "@ + id/main_btn4"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_margin = "15dp"
Android: layout_weight = "1"/>
</LinearLayout>
<RelativeLayout
Android: id = "@ + id/layout_menu"
Android: layout_width = "match_parent"
Android: layout_height = "200dp"
Android: layout_alignParentBottom = "true">
<LinearLayout
Android: id = "@ + id/menu"
Android: layout_width = "match_parent"
Android: layout_height = "40dp"
Android: background = "# dd000000"
Android: gravity = "center">
<TextView
Android: id = "@ + id/TV _main"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: gravity = "center"
Android: text = "common"
Android: textColor = "# ffffffff"/>
<TextView
Android: id = "@ + id/TV _utils"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: gravity = "center"
Android: text = "tool"
Android: textColor = "# ffffffff"/>
<TextView
Android: id = "@ + id/TV _set"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: gravity = "center"
Android: text = "Settings"
Android: textColor = "# ffffffff"/>
</LinearLayout>
<LinearLayout
Android: id = "@ + id/layout_anim"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_below = "@ + id/menu"
Android: background = "# eeff8c00">
<ImageView
Android: id = "@ + id/iv_cursor"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: scaleType = "matrix"
Android: src = "@ drawable/img_cursor"/>
</LinearLayout>
<Android. support. v4.view. ViewPager
Android: id = "@ + id/myPager"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_below = "@ + id/layout_anim"
Android: flipInterval = "30"
Android: persistentDrawingCache = "animation"/>
</RelativeLayout>
</RelativeLayout>

Xml of the three tabs in ViewPager
View_main.xml, view_set.xml, view_utils.xmlCopy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: background = "#77ff0000"
Android: orientation = "vertical">
<GridView
Android: id = "@ + id/myGridView"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: numColumns = "4"
Android: layout_margin = "10dp"
Android: horizontalSpacing = "20dp"
Android: gravity = "center"
Android: verticalSpacing = "20dp"
> </GridView>
</LinearLayout>

This is Tab 1 view_main.xml, and the other two are the same as this, so they will not be sent
Finally, there is a GirdView adapter xmlCopy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<ImageView
Android: id = "@ + id/imgbtn_img"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_centerHorizontal = "true"
/>
<TextView
Android: id = "@ + id/imgbtn_text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_below = "@ + id/imgbtn_img"
Android: layout_centerHorizontal = "true"
Android: text = "Text"
Android: textColor = "# ff0000ff"
Android: textSize = "10sp"/>
</RelativeLayout>

There are so many xml la S.

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.