Android VR Player(全景视频播放器) [3]:底部导航的实现
底部导航介绍
本篇主要分享Material design中Bottom Navigation的实现过程,先看效果图:
(图片来源:https://github.com/Ashok-Varma/BottomNavigation)
Bottom Navigation导航方式在今天很多APP上都可以看到,可以说是Android中的底部导航规范了,所以学习一下它的使用还是很有必要的。
实现步骤
添加依赖
在项目app的build.gradle文件的dependencies {}中添加
compile 'com.ashokvarma.android:bottom-navigation-bar:1.4.3'
然后同步一下配置
在布局中添加Bottom Navigation组件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="com.example.renkangchen.bottomnavigationbardeme.MainActivity">
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:id="@+id/bottom_navigation_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
(activity_main.xml代码片段)
上面是一个可参考的示例,注意BottomNavigationBar上面的FrameLayout,它用来“占位”,也就是把BottomNavigationBar“挤”到页面的底部