作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现一种布局,在这种布局中,我的 View 将一直延伸到整个屏幕,位于 ActionBar
下方。 , ActionBar 将是透明的。我还需要 ActionBar
和 BottomNavigationView
隐藏在滚动条上,所以我使用 CoordinatorLayout
.
我正在使用属性为 <item name="windowActionBarOverlay">true</item>
的 AppCompat 主题以便在 ActionBar 下扩展我的 View 。但是,在添加 app:layout_behavior="@string/appbar_scrolling_view_behavior"
之后对于我的容器 Fragment, View 被放置在 ActionBar 下方。
有没有办法防止这部分appbar_scrolling_behaviour
?我已经尝试过没有这种行为,但是 AppBar 的滚动与其下方的 RecyclerView 滚动不同步。谢谢!
这是一个 gif of the problem
P.S.:我正在尝试使用 Android 导航组件,所以如果这很重要,我将遵循一个单一的 Activity 、多 fragment 架构。
最佳答案
尝试此代码并进行一些更改,因为我使用的是 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>
关于android - 阻止 AppBarLayout.ScrollingViewBehavior 向 View 添加上边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55588173/
我是一名优秀的程序员,十分优秀!