android - 如何在底部导航栏添加一行
问题描述
我想在导航栏顶部添加一条线,类似于此处图像中的内容(除了这不是导航栏)。
我该怎么做呢?我需要添加线视图吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/tab_contents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_nav"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp">
</ScrollView>
<LinearLayout
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:orientation="horizontal">
<Button
android:id="@+id/nav_button1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
style="?android:attr/borderlessButtonStyle"
android:text="Home"/>
<Button
android:id="@+id/nav_button2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
style="?android:attr/borderlessButtonStyle"
android:text="Search"/>
</LinearLayout>
</RelativeLayout>
解决方案
添加高度为 1db 或 2db 的单个视图,并将其与底部视图的顶部对齐
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/tab_contents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_nav"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"></ScrollView>
<LinearLayout
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:orientation="horizontal">
<Button
android:id="@+id/nav_button1"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Home" />
<Button
android:id="@+id/nav_button2"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignTop="@+id/bottom_nav"
android:background="#C5C5C5" />
</RelativeLayout>
推荐阅读
- c++ - 如何从二维数组一起打印 int 和 char
- html - 如何在到期日更改字体颜色?
- amazon-s3 - S3 中的随机 Cloudfront 视频无法打开
- .net - Umbraco CMS 登录失败
- spring-boot - @FeignClient POST @RequestBody 映射
在 Spring Feign 中不起作用 - laravel - 如何检查laravel中是否存在通知
- compression - 精确控制数据块大小
- python - 在 Pygame 中如何使图像移动?
- flutter - 未处理的异常:错误状态:流已被收听
- powerbi - 无法发布到网络/公共