Android实现底部tabbar按钮突出效果

在某些情况下,我们可能需要使底部tabbar的中间按钮突出,即类似于如下的效果:


闲鱼底部tabbar按钮突出效果.png

在android要实现该效果,十分简单,只需要在按钮的父布局将android:clipChildren属性设置为false:

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:clipChildren="false">
    ...
  </RadioGroup>

并设置按钮的layout_gravity为bottom:

<RadioButton
    android:layout_width="match_parent"
    android:layout_height="90dp"
    android:layout_gravity="bottom" />

示例布局文件如下:

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:clipChildren="false">

    <RadioButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:drawableTop="@mipmap/ic_home"
        android:button="@null"
        android:text="首页" />

    <RadioButton
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:layout_gravity="bottom"
        android:drawableTop="@mipmap/ic_home"
        android:button="@null"
        android:text="精选" />
    
    <RadioButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:drawableTop="@mipmap/ic_home"
        android:button="@null"
        android:text="发布" />

   <RadioButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:drawableTop="@mipmap/ic_home"
        android:button="@null"
        android:text="发现" />

 <RadioButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:drawableTop="@mipmap/ic_home"
        android:button="@null"
        android:text="我的"/>

  </RadioGroup>

其中android:clipChildren属性的作用为是否限制子View不超过父布局,默认情况下是为true。当该属性为true时,子View超出父布局的部分会被裁剪。因此,将该属性设置为false,父布局不再裁剪子View超出父布局的部分,就能实现突出按钮的效果了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 11,935评论 0 17
  • 【Android 自定义View】 [TOC] 自定义View基础 接触到一个类,你不太了解他,如果贸然翻阅源码只...
    Rtia阅读 9,473评论 1 14
  • 说起来我看的第一本爱情小说应该算《射雕英雄传》,最初是在《武林》杂志上读的,每个月刊登一章,开始迷醉于丘处机和江南...
    卧龙饮水阅读 1,801评论 0 1
  • 我归罪于这个夜, 和这个时代。 我怪罪漆黑的夜, 不再有一丁点儿光亮。 遮蔽了光亮。 我怪罪这个时代, 不再有记忆...
    朱大饼阅读 1,432评论 0 0

友情链接更多精彩内容