Android底部导航栏中间凸起

很多APP底部导航都有这个效果,如图

效果图

这是布局:

<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:clipChildren="false"
    tools:context="com.yus.dialogdemo.MainActivity">

    <LinearLayout
        android:clipChildren="false"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal">
        
        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:src="@android:drawable/btn_star_big_on"
            />
        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:src="@android:drawable/btn_star_big_on"


            />
        <ImageView
            android:scaleType="centerCrop"
            android:layout_gravity="bottom"
            android:layout_width="0dp"
            android:layout_height="75dp"
            android:layout_weight="1"
            android:src="@android:drawable/btn_star_big_on">

        </ImageView>

        <ImageView

            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:src="@android:drawable/btn_star_big_on"></ImageView>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:src="@android:drawable/btn_star_big_on"></ImageView>

    </LinearLayout>
</RelativeLayout>

** android:clipChildren="false"**的意思是孩子的宽高不必受父亲的约束,即可大过父布局,父亲以及父亲的父亲都必须申明才可以,中间Imageview的android:layout_gravity="bottom"表示当高度超过父布局时,底部对齐,于是就达到上图的效果。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,977评论 25 708
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,489评论 2 45
  • 或近或远 或清或浅 在亦或不在 时光转角处 原来的模样 依旧清晰如初 放一枝梦魇 辗转在岁月深处 轮回,轮回 于心...
    四季叶阅读 158评论 0 0
  • 前两天知乎上有一个非常火的话题,话题内容是这样的:“13,14岁的青少年如何在生活中培养国际视野”,看法和观点在博...
    i老毕阅读 203评论 0 2
  • 期待已久的牛剑之旅开始啦,今天先游剑桥大学,剑桥,英文Cambridge,剑河之桥的意思。地导李老师提示孩子们剑桥...
    April_0831阅读 215评论 0 0