BottomTabBar

说明:此控件是在Jack Tony: 的BottomTabBar项目基础上进行的改造,原项目地址:https://github.com/tianzhijiexian/BottomTabBar。在此表示感谢。

主要是由于原项目中,tab采用drawable top 和 radio button形式,无法灵活控制drawable的大小及drawable与文字之间的间距,现采用自定义的RadioImageView实现tab上的drawable,RadioTextView实现tab的标题。

效果图

底部tab切换栏。完全模仿了RadioGroup的机制,提供了可以扩展的接口

BottomTabGroup完全模仿了RadioGroup的机制,你可以理解为它是RadioGroup的增强版本,它内部的view不再仅限于RadioButton了,而是实现了BottomTabImpl这个接口的的任何view。这样我们可以很容易的用自定义控件来做类似RadioButton的效果了,自然而然就能有更多的扩展性。

如何使用

引入library

```

dependencies {

compile 'com.frozy:bottombar:1.0'

}

```

1.首先在布局中像放RadioGroup时放一个BottomTabGroup:

android:id="@+id/bottom_bar_root"

android:layout_width="match_parent"

android:layout_height="54dp"

android:layout_alignParentBottom="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:background="@drawable/list_vertical_root_bg"

android:orientation="horizontal"

android:paddingTop="5dp"

>

android:id="@+id/tab_01"

style="@style/bottomTab"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

app:drawableTop="@drawable/main_bottombar_icon_home_selector"

app:tabText="tab01"/>

android:id="@+id/tab_02"

style="@style/bottomTab"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

app:hintEnable="false"

app:drawableTop="@drawable/main_bottombar_icon_home_selector"

app:tabText="tab02"/>

android:id="@+id/tab_03"

style="@style/bottomTab"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

app:drawableTop="@drawable/main_bottombar_icon_home_selector"

app:tabText="tab03"/>

android:id="@+id/tab_04"

style="@style/bottomTab"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

app:drawableTop="@drawable/main_bottombar_icon_home_selector"

app:tabText="tab04"/>

2.style/bottomTab定义

@color/main_bottombar_text_selector

12sp

@android:color/white

3sp

@drawable/red_hint

true

6dp

设置属性

如果你用的是包中提供的BottomTab的话,那么参考以上使用示例, 有下面这几个属性可以设置:

app:tabText:设置按钮下方的文字

app:tabTextColor:设置按钮的颜色

app:drawableTop:设置按钮中的图片

app:tabTextSize: 设置按钮文字大小

app:hintText:设置角标文字

app:hintTextColor:设置角标文字颜色

app:hintTextSize:设置角标文字大小

app:hintTextBackground:设置角标背景

app:hintEnable:设置是否显示角标

app:verticalSpace:设置按钮文字与图片的垂直间距, 图片会自适应大小

扩展

前面说到了BottomTab就是一个具体的实现类,我们完全可以用自定义View的方式来做出自己的按钮和红点来,下面推荐两种实现方式,可以按需求来做。

1.继承BottomTab**(简单)**

继承BottomTab这个类,然后复写getLayoutRes()这个方法,传入你自定义的一个layout的id:

public class TestView extends BottomTab{

public TestView(Context context, AttributeSet attrs) {

super(context, attrs);

}

public TestView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

}

@Override

public int getLayoutRes() {

return R.layout.test_main;

}

}

在这个layout中你必须要放入一个id为:tab_btn和tab_hint的两个View,其中一个是RadioButton,一个是TextView。这样id为tab_hint的TextView就可以做红点提示,而id为tab_btn的RadioButton就可以做实体的按钮了。需要注意的是BottomTab这个view是继承自RelativeLayout的,所以在做布局的时候需要注意下控件摆放的位置。为了减少布局的层次,你还可以用merge标签。就像下面的写法:

>

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1"

>

android:id="@id/tab_icon"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:layout_centerInParent="true"

/>

android:id="@id/tab_hint"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_marginLeft="-5dp"

android:layout_toRightOf="@id/tab_icon"

android:paddingLeft="4dp"

android:paddingRight="4dp"

android:singleLine="true"

android:textSize="11sp"

/>

android:id="@id/tab_title"

android:gravity="center"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:singleLine="true"/>

2.实现BottomTabImpl**(扩展性强)**

自定义一个view实现BottomTabImpl这个接口,然后请模仿BottomTab的写法进行编写。这样的方式是需要重新编写一些按钮点击事件,但是扩展性是最强的。

License

Copyright 2015 Jack Tony

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

android 位于底部的tab,GitHub - DevinFu/BottomTabBar: Android应用中位于底部的tab栏相关推荐

  1. android苹果音乐播放器,GitHub - macproz/HappyMusicPlayer: android音乐播放器

    ====================== 2015-03-11 ===================== 1.完成了基本的页面 ====================== 2015-03-1 ...

  2. android 仿照ios 图片选择,GitHub - wildma/PictureSelector: Android 图片选择器(仿 IOS 图片选择控件)...

    PictureSelector Android 图片选择器(仿 IOS 图片选择控件) 效果图 功能特点 支持通过拍照获取图片 支持通过相册获取图片 支持图片是否裁剪两种场景 支持仿 IOS 底部弹出 ...

  3. 智能android电视更换播放器,GitHub - qfwc258/TvPlayer: android智能电视播放器,可以播放各电视台节目,播放基于ijkplayer的实现。...

    TvPlayer 1,android智能电视播放器,可以播放各电视台节目,播放基于ijkplayer的实现 2,测试的源地址可能失效,如需测试可以自己更换播放源.HttpUtils.getOfflin ...

  4. android相机横屏竖屏,GitHub - qixuefeng/CameraAdapt: Android相机屏幕适配

    CameraAdaptDemo Android相机屏幕适配 该项目主要是为了做相机下的屏幕适配 具体思路可以参见我的这篇文章 Android 相机屏幕适配 测试: 机型:华为荣耀8 (厂商:honor ...

  5. android rsa加密工具类,GitHub - Lerist/encrypt: Android 加密解密工具包。

    Encrypt(加密工具) 字符串,byte[],文件等对象的加密和解密工具集合,包含了多种加密方案. 加密类型 摘要 相关方法 简单加密 换一种编码格式 Base64Util 单向加密 只能加密,不 ...

  6. android live 电视 源码,GitHub - mxiaoguang/LivePlayback: Android TV直播电视节目 ,包含各央视频道及卫视频道...

    Android TV直播电视节目 更多技术博客,项目,欢迎关注公众号: Android TV开发交流群:135622564 传统电视直播节目,在Android TV上起着越来越重要的作用,央视,各地卫 ...

  7. android瀑布流布局源码,GitHub - dodola/android_waterfall: Android版的瀑布流布局

    Android瀑布流实例 此项目由于最初设计问题,导致现在问题比较多,暂时停止维护. 我现在在其他类似的瀑布流上进行完善开发, ####请关注: 有必要解释一下程序为什么采用addview方式而不是做 ...

  8. 智能android电视更换播放器,GitHub - kaigeLove/TvPlayer: android智能电视播放器,可以播放各电视台节目,播放基于ijkplayer的实现。...

    TvPlayer 1,android智能电视播放器,可以播放各电视台节目,播放基于ijkplayer的实现 2,测试的源地址可能失效,如需测试可以自己更换播放源.HttpUtils.getOfflin ...

  9. 智能android电视更换播放器,GitHub - xioxu/TvPlayer: android智能电视播放器,可以播放各电视台节目,播放基于ijkplayer的实现。...

    TvPlayer 1,android智能电视播放器,可以播放各电视台节目,播放基于ijkplayer的实现 2,测试的源地址可能失效,如需测试可以自己更换播放源.HttpUtils.getOfflin ...

最新文章

  1. python导出csv不带引号的句子_python csv writer在不需要时添加引号
  2. 中国航发牵手阿里云共同打造:航空新引擎
  3. linux inode100%
  4. C#怎么遍历一个对象里面的全部属性?
  5. win10弹不出密码输入框_电脑互访提示输入网络密码,怎么办?
  6. 吐槽一下Abp的用户和租户管理模块
  7. Redis学习之Docker环境搭建
  8. 安装ssd后不识别网卡_100元体验纯正万兆网络:需要安装SSD的NAS服务器
  9. mysql并发 node_nodejs写入mysql单次数据量过大的解决方法_沃航科技
  10. mysql 40014无效_Oracle 问题-ORA-14400: 插入的分区关键字未映射到任何分区
  11. 彭博社推出“机器学习基础”课程
  12. javaWEB的三大组件(入门基础总结)
  13. Vs2010 Qt插件安装教程
  14. [大数据 ]Apache大数据项目目录
  15. IDA install keystone
  16. 算法题9-最短路径问题-Dijkstra算法
  17. 边缘计算平台能力开放
  18. 莱西姆大学计算机专业,菲律宾的大学排名是根据什么指标排的
  19. Centos清理内存 内存回收释放及内存使用查看的相关命令
  20. 算法小讲堂之哈希表|散列表|考研笔记

热门文章

  1. java程序设计课程培训心得体会_20165226 2017-2018-2《Java程序设计》课程总结
  2. 最近很火的拼购,模式剖析—微三云贺心悦
  3. 002 Ubuntu系统设置之调整界面大小
  4. aop - spring如何选择、创建代理bean
  5. Revit二次开发——Ribbon菜单的创建以及各种不同的button(按钮)的代码总结
  6. Matlab 图片转gif
  7. Qt论坛和博客网址大全
  8. Graphviz画决策树中文乱码解决
  9. 4S店维修陷阱 零配件以换代修成潜规则
  10. 迅雷无法下载的解决方法