Reputation: 145
As said in the title, I have a problem with my bottom sheet.
What I want in my bottom sheet is a RecyclerView with dynamic items that can change anytime. There is also components before and after the RecyclerView. For convenience, I put a fragment in the bottom sheet.
Here is my bottom sheet :
<android.support.v4.widget.NestedScrollView
android:id="@+id/bsControllers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_peekHeight="@dimen/controllerPeekHeight"
app:layout_behavior="@string/bottom_sheet_behavior">
<FrameLayout
android:id="@+id/flBsContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"/>
</android.support.v4.widget.NestedScrollView>
And here is my Fragment :
<android.support.constraint.ConstraintLayout
android:id="@+id/clControllerSheetRoot"
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="wrap_content"
android:background="@color/colorPrimary"
tools:context="fr.mld.dmg.view.fragment.ControllerSheetFragment">
<View
android:id="@+id/vPeek"
android:layout_width="0dp"
android:layout_height="@dimen/controllerPeekHeight"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@color/green"/>
<ProgressBar
android:id="@+id/pbControllerScan"
android:layout_width="0dp"
android:layout_height="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vPeek"/>
<ImageView
android:id="@+id/ivBle"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="8dp"
android:src="@drawable/ic_thread_online"
app:layout_constraintBottom_toBottomOf="@+id/vPeek"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/vPeek"/>
<ImageView
android:id="@+id/ivExpansionIndicator"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="8dp"
android:src="@drawable/ic_arrow_down"
android:tint="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/vPeek"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/vPeek"/>
<TextView
android:id="@+id/tvControllerCount"
style="@style/BoldWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/vPeek"
app:layout_constraintEnd_toStartOf="@+id/ivLight"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="@+id/ivBle"
app:layout_constraintTop_toTopOf="@+id/vPeek"
tools:text="3"/>
<ImageView
android:id="@+id/ivLight"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_light_unselected"
android:tint="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/vPeek"
app:layout_constraintEnd_toStartOf="@+id/tvConnected"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/tvControllerCount"
app:layout_constraintTop_toTopOf="@+id/vPeek"/>
<TextView
android:id="@+id/tvConnected"
style="@style/BoldWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connected"
android:textAllCaps="true"
app:layout_constraintBottom_toBottomOf="@+id/vPeek"
app:layout_constraintEnd_toStartOf="@+id/ivExpansionIndicator"
app:layout_constraintStart_toEndOf="@+id/ivLight"
app:layout_constraintTop_toTopOf="@+id/vPeek"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvControllers"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/bConnectAll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vPeek"/>
<Button
android:id="@+id/bConnectAll"
style="@style/Button.ButtonWhiteStroke"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:text="@string/connect_all"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/bUpdateAll"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"/>
<Button
android:id="@+id/bUpdateAll"
style="@style/Button.ButtonWhiteStroke"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="8dp"
android:text="@string/update_all"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bConnectAll"/>
<View
android:id="@+id/vTagUpdate"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginEnd="4dp"
android:layout_marginTop="4dp"
android:background="@drawable/tag_warning"
app:layout_constraintEnd_toEndOf="@+id/bUpdateAll"
app:layout_constraintTop_toTopOf="@+id/bUpdateAll"/>
</android.support.constraint.ConstraintLayout>
My problem
On first launch, the bottom sheet is scrolled down by the peek height. When I expand it then collapse it, it isn't scrolled down by the peek height. Also, it happens only when my RecyclerView has too much items to fit in the screen height, otherwise it works just fine.
What I already tried
I'm really lost here and I really don't know what to do anymore. Any help will be much appreciated.
EDIT A video to be more clear about my problem : https://youtu.be/y8KhKW9KS_E
Upvotes: 2
Views: 958
Reputation: 145
After following the lead of @Cheticamp, I finally figured where the problem was. At creation, it seems that the RecyclerView is getting focused, causing the NestedScrollView to scroll to the top of it.
All I had to do was to give android:focusableInTouchMode="true"
to the green background view of my layout. Then, it takes the focus first and doesn't scroll to the top of the RecyclerView.
Many thanks to everyone who helped me figure it out !
Upvotes: 0