当前位置: 首页 > news >正文

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

BottomTabBar

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

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

效果图

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

4bb8d4f4d4eac684d15fdc5d6732ecdd.png

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 studio 程序包r不存在,Android Studio问题!无法解析符号R,找不到与...
  • 麒麟810鸿蒙内核移植,2K魅眼屏+鸿蒙OS系统+麒麟810 华为出大招了
  • C51编程语言的特点 与C的异同点,编程语言异同点归纳之一:注释方法 | 求索阁...
  • 华为鸿蒙系统启示,华为的机遇——鸿蒙系统启示录
  • signature=9721a1ecae6007cb6671337ee094b6b3,Nature Rev Immunol. The dark side of C5a in sepsis
  • html区域滚动原理,实例帮助你了解HTML5滑动区域选择元素Slider element
  • html的语义化怎么理解,关于语义化的HTML结构怎么理解
  • html转换成纯文本,你如何将Html转换为纯文本?
  • html的confirm弹窗样式修改,H5-Mui框架——修改mui.confirm样式
  • html三行三列模式布局,一个CSS上中下三行三列结构的Div布局
  • 2021遂宁高考成绩多久查询,2021年遂宁如何查询中考成绩
  • ncp计算机网络,计算机网络(待完成)
  • 计算机专业的口号运动会四字,运动会口号四字
  • 给div赋html,jquery怎么给div赋值
  • koa渲染html文件,Koa 中返回 html 文件引发的思考-一一网络
  • ES6指北【2】—— 箭头函数
  • Android 初级面试者拾遗(前台界面篇)之 Activity 和 Fragment
  • Android路由框架AnnoRouter:使用Java接口来定义路由跳转
  • Angular6错误 Service: No provider for Renderer2
  • JAVA_NIO系列——Channel和Buffer详解
  • node学习系列之简单文件上传
  • react-native 安卓真机环境搭建
  • Spring核心 Bean的高级装配
  • Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
  • 原生js练习题---第五课
  • kubernetes资源对象--ingress
  • Semaphore
  • 从如何停掉 Promise 链说起
  • 新年再起“裁员潮”,“钢铁侠”马斯克要一举裁掉SpaceX 600余名员工 ...
  • 移动端高清、多屏适配方案
  • ​RecSys 2022 | 面向人岗匹配的双向选择偏好建模
  • ​猴子吃桃问题:每天都吃了前一天剩下的一半多一个。
  • # Pytorch 中可以直接调用的Loss Functions总结:
  • #pragma 指令
  • #QT(智能家居界面-界面切换)
  • #中国IT界的第一本漂流日记 传递IT正能量# 【分享得“IT漂友”勋章】
  • (27)4.8 习题课
  • (pt可视化)利用torch的make_grid进行张量可视化
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (力扣)循环队列的实现与详解(C语言)
  • (十八)三元表达式和列表解析
  • (四)图像的%2线性拉伸
  • (译) 理解 Elixir 中的宏 Macro, 第四部分:深入化
  • (原创)Stanford Machine Learning (by Andrew NG) --- (week 9) Anomaly DetectionRecommender Systems...
  • .bat批处理(四):路径相关%cd%和%~dp0的区别
  • .net core使用ef 6
  • .NET 反射的使用
  • @Import注解详解
  • @Repository 注解
  • []我的函数库
  • [BSGS算法]纯水斐波那契数列
  • [C# WPF] 如何给控件添加边框(Border)?
  • [CF407E]k-d-sequence
  • [CSDN首发]鱿鱼游戏的具体玩法详细介绍
  • [Deep Learning] 神经网络基础