问题描述
我在一个屏幕上有折叠的工具栏和底部工作表。底部工作表有一些窥视高度,因此用户可以拖动底部工作表。 但这里的问题是当我尝试拖动和滚动底部工作表时,折叠工具栏也在滚动,主屏幕上的内容也随着底部工作表内容滚动。
我的活动 UI 代码如下所示:
<?xml version="1.0" encoding="utf-8"?>
<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">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#ff0000">
<TextView
android:id="@+id/introducing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="introducing"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentScrim="@color/purple_200"
app:layout_collapseMode="pin"
app:statusBarScrim="#aabb00">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.nestedScrollView
android:id="@+id/info_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/design_default_color_primary"
android:scrollbars="none"
app:layout_behavior="@string/bottom_sheet_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="some scrolling text" />
</androidx.core.widget.nestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我的活动代码如下:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val info_bottom_sheet = findViewById<nestedScrollView>(R.id.info_bottom_sheet)
val sheetBehavior: BottomSheetBehavior<nestedScrollView> = BottomSheetBehavior.from(info_bottom_sheet)
sheetBehavior.isFitToContents = true // the default
sheetBehavior.peekHeight = 200
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View,newState: Int) {
}
override fun onSlide(bottomSheet: View,slideOffset: Float) {}
})
}
}
有什么办法可以解决这个问题吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)