【发布时间】:2017-12-01 10:14:41
【问题描述】:
我将如何为底部工作表提供底部边距。
XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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/bottomSheet"
android:background="@android:color/white"
android:paddingTop="@dimen/activity_horizontal_margin"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/bottomSheetRecyclerview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
实现代码:
override fun openBottomDialogView() {
val bottomSheetView= findViewById<NestedScrollView>(R.id.bottomSheet) as NestedScrollView
Log.e("Bottom sheet view ",bottomSheetView.toString())
dashboardBottomSheetBehaviour = BottomSheetBehavior.from(bottomSheetView)
dashboardBottomSheetBehaviour.isHideable=true
if(dashboardBottomSheetBehaviour.getState() != BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetRecyclerview.layoutManager= LinearLayoutManager(this@DashboardActivity) as RecyclerView.LayoutManager?
bottomSheetRecyclerview.adapter= BottomSheetDialogAdaptor(this@DashboardActivity, getBottomSheetitem())
dashboardBottomSheetBehaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
}
else {
closeBottomView()
}
}
我尝试设置 nestedscrollview 的固定高度,然后给出边距,但这也没有用。
关于我面临的新问题
fun closedBottomView(){
Log.e("CLose ","Old bottom sheet")
dashboardBottomSheetBehaviour.state=BottomSheetBehavior.STATE_HIDDEN
Log.e("Final state ",dashboardBottomSheetBehaviour.state.toString())
}
这里的最终日志显示底部工作表状态为 STATE_SETTLING。但是回调在隐藏状态下说它。
【问题讨论】:
标签: android bottom-sheet android-nestedscrollview