繁体   English   中英

防止AppBarLayout.ScrollingViewBehavior向视图添加上边距?

[英]Prevent AppBarLayout.ScrollingViewBehavior from adding top margin to the view?

我正在尝试实现一种布局,该视图的视图将一直延伸到整个屏幕,在ActionBar ,并且ActionBar将是透明的。 我还需要ActionBarBottomNavigationView来隐藏在滚动条上,所以我正在使用CoordinatorLayout

我正在将AppCompat主题与属性<item name="windowActionBarOverlay">true</item> ,以使视图在ActionBar下扩展。 但是,在将app:layout_behavior="@string/appbar_scrolling_view_behavior"到我的容器Fragment之后,视图被放置在ActionBar下方。

有没有办法防止appbar_scrolling_behaviour这一部分? 我尝试了没有这种行为,但是AppBar的滚动与它下面的RecyclerView滚动不同步。 谢谢!

是问题gif

PS:我正在尝试使用Android导航组件,因此,如果需要的话,我将遵循单一活动,多片段架构。

尝试此代码并进行一些更改,因为我使用了androidx ..这样的主布局。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">


<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/white"
        android:theme="@style/MyToolbar"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp"
        app:titleTextAppearance="@style/MyToolbar">

        <ImageView
            android:id="@+id/headerIcon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_6sdp"
            android:src="@drawable/ic_edit_location_black"
            android:visibility="gone" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_6sdp">

            <TextView
                android:id="@+id/header"
                style="@style/MyToolbar"
                android:layout_width="wrap_content"
                android:layout_height="?attr/actionBarSize"
                android:gravity="center_vertical"
                android:textColor="@color/primary"
                app:layout_constraintStart_toStartOf="parent" />

            <ImageView
                android:id="@+id/ivSearch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/_10sdp"
                android:src="@drawable/search_icon"
                android:visibility="gone"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.appcompat.widget.Toolbar>


</com.google.android.material.appbar.AppBarLayout>

<FrameLayout
    android:id="@+id/activity_main_container"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@+id/bottomContainer"
    app:layout_constraintTop_toBottomOf="@+id/appBarLayout" />


    <RelativeLayout
       android:id="@+id/bottomContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bvTabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/Widget.BottomNavigationView"
            app:itemIconTint="@drawable/navigation_drawable_tint"
            app:itemTextColor="@drawable/navigation_drawable_tint"
            app:menu="@menu/bottom_menu_item" />


    </RelativeLayout>

 </androidx.constraintlayout.widget.ConstraintLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM