【问题标题】:Fragment (ScrollView) Covering Bottom NavView Items覆盖底部 NavView 项的 Fragment (ScrollView)
【发布时间】:2021-05-24 15:34:54
【问题描述】:

我有一个带有 ScrollView 和 BottomNavBar 的片段,片段从中膨胀,但是当编译 ScrollView 覆盖底部导航栏时无法使用如何将片段的内容限制为仅离开屏幕的其余部分底部导航栏原样。

底部导航栏活动代码

    <?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>

输出 - Final Result of Above XML

【问题讨论】:

    标签: android android-studio android-layout android-fragments android-scrollview


    【解决方案1】:

    在 Fragment xml 代码中父线性布局的底部添加以下代码

     <View
        android:layout_width="match_parent"
        android:layout_height="80dp">
    
    </View>
    

    希望它会起作用......

    【讨论】:

    • 感谢这个作品!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多