由于NestedScrollView,BottomSheet`STATE_EXPANDED`被过早设置

时间:2018-06-19 15:59:49

标签: android android-layout android-support-library android-support-design

我的底部工作表视图出现奇怪的故障,导致其过早扩展。

S3

之所以会这样,是因为我们在布局的其他地方使用了// from `BottomSheetBehavior.java` (line 384) @Override public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) { if (child.getTop() == mMinOffset) { // this line gets called when the bottom sheet has *NOT* been expanded, causing it to expand setStateInternal(STATE_EXPANDED); return; }

XML

我有以下活动XML,该XML具有用于片段和3个底页的内容框架。

NestedScrollView

我的底页工作正常,直到我完成将<android.support.design.widget.CoordinatorLayout android:id="@+id/activity_root" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.CoordinatorLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize" /> <FrameLayout android:id="@+id/bottomSheet1" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="5dp" app:behavior_peekHeight="0dp" app:layout_behavior="android.support.design.widget.BottomSheetBehavior" /> <FrameLayout android:id="@+id/bottomSheet2" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="5dp" app:behavior_peekHeight="0dp" app:layout_behavior="android.support.design.widget.BottomSheetBehavior" /> <FrameLayout android:id="@+id/bottomSheet3" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="5dp" app:behavior_peekHeight="0dp" app:layout_behavior="android.support.design.widget.BottomSheetBehavior" /> </android.support.design.widget.CoordinatorLayout> 设置为以下内容的片段事务为止。

@id/fragment_container

<android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <android.support.constraint.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/header" android:layout_width="0dp" android:layout_height="wrap_content" android:text="some text" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> <android.support.v7.widget.RecyclerView android:id="@+id/recycler" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/header" /> <!-- Intentionally use sp for height so that it will expand if user increases text size --> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="start" android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" android:minHeight="56dp" android:text="some text" android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/recycler" /> </android.support.constraint.ConstraintLayout> </android.support.v4.widget.NestedScrollView> 切换到NestedScrollView可以解决此问题,但是会导致ScrollView(即RecyclerView)出现问题,因此需要将其放在{ {1}}(https://stackoverflow.com/a/37338715/891242

除了使用多种视图类型将wrap_content设置为NestedScrollView(我真的不愿意)以外,我还可以采取其他措施来解决此问题?

0 个答案:

没有答案