Android仿UC底部菜单栏实现原理与代码

相关的链接:

Android 底部菜单栏实现

最近刚看完ViewPager,就想到做这样一个Demo,当然也参考了高手们的实例里边的网格菜单,开始我打算用自定义的imgBtn,但是发现放在pager选项卡中不好排版,所以最好选了GridView,简单实用

一、先主界面xml

activity_main.xml

复制代码 代码如下:

<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="常用"

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="工具"

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="设置"

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>

ViewPager中的三个选项卡xml

view_main.xml,view_set.xml,view_utils.xml

复制代码 代码如下:

<?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>

这是选项卡一view_main.xml,后面的两个和这个一样,就不发了

最后就是还有一个GirdView的适配器xml

复制代码 代码如下:

<?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>

xml布局部分就这么多了

时间: 2024-07-31 22:59:10

Android仿UC底部菜单栏实现原理与代码的相关文章

Android仿UC底部菜单栏实现原理与代码_Android

相关的链接: Android 底部菜单栏实现 最近刚看完ViewPager,就想到做这样一个Demo,当然也参考了高手们的实例里边的网格菜单,开始我打算用自定义的imgBtn,但是发现放在pager选项卡中不好排版,所以最好选了GridView,简单实用 一.先主界面xml activity_main.xml 复制代码 代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

Android仿微信底部菜单栏功能显示未读消息数量_Android

底部菜单栏很重要,我看了一下很多应用软件都是用了底部菜单栏,这里使用了tabhost做了一种通用的(就是可以像微信那样显示未读消息数量的,虽然之前也做过但是layout下的xml写的太臃肿,这里去掉了很多不必要的层,个人看起来还是不错的,所以贴出来方便以后使用). 先看一下做出来之后的效果: 以后使用的时候就可以换成自己项目的图片和字体了,主框架不用变哈哈, 首先是要布局layout下xml文件 main.xml: <?xml version="1.0" encoding=&qu

Android仿微信底部菜单栏效果

前言 在市面上,大多数的APP都需要通过底部菜单栏来将程序的功能进行分类整理,通常都是分为3-5个大模块,从而正确有效地引导用户去使用我们的APP.实现底部菜单栏的方法也有很多种. 1.仿微信底部菜单栏(ViewPager+ImagerView+TextView) ......(其他方式后续会补充) 效果预览 首先来个开胃菜,看看实现效果: 先贴出项目所需的资源文件,这些可随个人自由更改颜色和文字 colors.xml <color name="bg_line_light_gray&quo

android底部菜单栏实现原理与代码_Android

上一个项目已经做完了,这周基本上没事,所以整理了下以前的项目,想把一些通用的部分封装起来,这样以后遇到相似的项目就不用重复发明轮子了,也节省了开发效率.今天把demo贴出来一是方便以后自己查询,二是希望同时也能帮到大家. 底部菜单栏很重要,我看了一下很多应用软件都是用了底部菜单栏做.我这里使用了tabhost做了一种通用的(就是可以像微信那样显示未读消息数量的,虽然之前也做过但是layout下的xml写的太臃肿,这里去掉了很多不必要的层,个人看起来还是不错的,所以贴出来方便以后使用). 先看一下

android底部菜单栏实现原理与代码

上一个项目已经做完了,这周基本上没事,所以整理了下以前的项目,想把一些通用的部分封装起来,这样以后遇到相似的项目就不用重复发明轮子了,也节省了开发效率.今天把demo贴出来一是方便以后自己查询,二是希望同时也能帮到大家. 底部菜单栏很重要,我看了一下很多应用软件都是用了底部菜单栏做.我这里使用了tabhost做了一种通用的(就是可以像微信那样显示未读消息数量的,虽然之前也做过但是layout下的xml写的太臃肿,这里去掉了很多不必要的层,个人看起来还是不错的,所以贴出来方便以后使用). 先看一下

Android仿UC浏览器左右上下滚动功能_Android

本文要解决在侧滑菜单右边加个文本框,并能实现文本的上下滑动和菜单的左右滚动.这里推荐可以好好看看android的触摸事件的分发机制,这里我就不详细讲了,我只讲讲这个应用.要实现的功能就像UC浏览器(或其它手机浏览器)的左右滚动,切换网页,上下滚动,拖动内容. 本文的效果:   一.功能要求与实现1.功能要求:(1)手指一开始按着屏幕左右移动时,只能左右滚动菜单,如果这时手指一直按着,而且上下移动了,那么菜单显示部分保持不变,但文本框也不上下移动!                       (2

Android仿UC浏览器左右上下滚动功能

本文要解决在侧滑菜单右边加个文本框,并能实现文本的上下滑动和菜单的左右滚动.这里推荐可以好好看看android的触摸事件的分发机制,这里我就不详细讲了,我只讲讲这个应用.要实现的功能就像UC浏览器(或其它手机浏览器)的左右滚动,切换网页,上下滚动,拖动内容. 本文的效果: 一.功能要求与实现 1.功能要求: (1)手指一开始按着屏幕左右移动时,只能左右滚动菜单,如果这时手指一直按着,而且上下移动了,那么菜单显示部分保持不变,但文本框也不上下移动!                       (2

Android仿微信底部按钮滑动变色

Android仿微信底部按钮滑动变色,这里只针对使用Fragment为Tab页的滑动操作,进行简单的变色讲解. 首先说下OnPageChangeListener这个监听 //这个监听有三个方法 public abstract void onPageScrollStateChanged (int state) public abstract void onPageScrolled (int position, float positionOffset, int positionOffsetPixe

Android仿美团分类下拉菜单实例代码_Android

本文实例为大家分享了Android仿美团下拉菜单的实现代码,分类进行选择,供大家参考,具体内容如下 效果图 操作平台 AS2.0 第三方框架:butterknife build.gradle dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile