【发布时间】:2021-09-28 05:23:38
【问题描述】:
我想在我的 AppBarLayout 中的 Toolbar 和 TabLayout 之间插入一个图像(蓝色的 imageView)。当您向上滚动时,应始终显示 TabLayout 和 Toolbar。仅当您滚动到页面顶部时才应显示图像。 但是,我遇到的问题是图像总是阻塞或阻碍顶部工具栏。有谁知道如何解决这个问题?
代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Site.MainPage">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/mainPage_appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/mainPage_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/UpperToolbarBackground"
app:layout_scrollFlags="scroll|enterAlways">
<TextView
android:id="@+id/mainPage_toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionToolBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Test"
android:textColor="@color/UpperToolbarText" />
</androidx.appcompat.widget.Toolbar>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll">
<ImageView
android:id="@+id/mainPage_profile_picture"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/blue_700"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/mainPage_tabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_margin="0dp"
app:layout_scrollFlags="noScroll"
app:tabMode="auto" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/mainPage_nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintTop_toBottomOf="@id/mainPage_appBar">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/mainPage_viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:nestedScrollingEnabled="true" />
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
示例图片:
怎么样:
开始
向下滚动
向上滚动一点(这是问题所在)
应该是这样的:
【问题讨论】:
-
在您的情况下,视图寻呼机是否也有滚动内容?
-
是的。在这种情况下(用于测试),它是 NestedScrollView 中的 TextView。
标签: java android xml android-toolbar android-appbarlayout