android - 覆盖底部 NavView 项的 Fragment (ScrollView)
问题描述
我有一个带有 ScrollView 和 BottomNavBar 的 Fragment,从该 Fragment 膨胀但是当编译 ScrollView 覆盖时,底部导航栏制作不可用如何将 Fragment 的内容限制为仅屏幕的其余部分,将底部导航栏保留为这是。
BottomNav 栏活动代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/landing_page_body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".pages.LandingPage"
tools:openDrawer="start">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:transformPivotX="100dp"
app:labelVisibilityMode="unlabeled"
app:menu="@menu/bottom_navbar_menu"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/side_navbar_header"
app:menu="@menu/side_navbar_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
片段 xml 代码
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false">
<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=".fragments.auction_add">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="5dp"
android:paddingTop="20dp"
android:text="Enter Auction Details -"
android:textSize="40dp"></TextView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingVertical="5dp">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"></ImageView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:gravity="center"
android:paddingHorizontal="15dp"
android:paddingVertical="5dp">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_gravity="end"
android:background="@drawable/rounded_edittext"
android:gravity="center"
android:hint="Name of Item"
android:maxLines="1"
android:overScrollMode="ifContentScrolls" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingHorizontal="20dp"
android:paddingVertical="5dp">
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="@drawable/rounded_edittext"
android:gravity="center"
android:hint="Description"
android:maxLength="40"
android:maxLines="5"
android:minHeight="100dp"
android:overScrollMode="ifContentScrolls"
android:padding="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingVertical="5dp">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:background="@drawable/rounded_edittext"
android:gravity="center"
android:hint="Initial Price"
android:maxLines="1"
android:overScrollMode="ifContentScrolls" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingVertical="5dp">
<EditText
android:id="@+id/startTimePicker"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="@drawable/rounded_edittext"
android:gravity="center"
android:hint="Start Time"
android:maxLines="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingVertical="5dp">
<EditText
android:id="@+id/endTimePicker"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="@drawable/rounded_edittext"
android:gravity="center"
android:hint="End Time"
android:maxLines="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginVertical="30dp"
android:gravity="center"
android:paddingVertical="5dp">
<Button
android:layout_width="200dp"
android:layout_height="50dp"
android:background="@drawable/rounded_edittext"
android:text="Post Item" />
</LinearLayout>
</LinearLayout>
</ScrollView>
输出 - 以上 XML 的最终结果
解决方案
在 Fragment xml 代码的父线性布局底部添加以下代码
<View
android:layout_width="match_parent"
android:layout_height="80dp">
</View>
希望它会工作...
推荐阅读
- vagrant - Metasploit:使用打包程序构建 vagrant box 时出错
- java - 进一步优化交换
- flutter - Flutter Firestore 按产品名称即时搜索
- java - 如何让 java 只接受数字 1-5 的用户输入?
- python - AttributeError:模块“mnist”没有属性“train_images”
- rust - std::task::Context 中使用的标记字段(PhatomData)是什么?
- react-native - React 钩子/生命周期导航 React-native
- apache - .htaccess https、www 和子域静默重写
- python-3.x - 井字游戏模式有问题?
- python - python列表中的元素总和