0

Targeting androidx 1.0.0 to allow for pre-Lollipop devices (let's say minSdkVersion 17 or so).

I have tried many combinations of views, settings, scrolling modes and layout managers. I have read everything - e.g. this and this and this - regarding this problem. Either I get bad layout/rendering performance or incorrect/buggy scrolling.

Requirements:

  1. A bottomsheet is draggable from the bottom. A common UI pattern in modern apps.
  2. 10-20 heavy equally sized child views. These must not be inflated/drawn when invisible.
  3. Using native Android/Google views is preferable.

How can I achieve this?

Here's some pseudo code, showing what I'm trying to accomplish; a RecyclerView (or equivalent) inside a NestedScrollView with a BottomSheetBehavior:

<ScrollView>
  <!-- Main content -->
</ScrollView>
<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:fitsSystemWindows="true"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
    app:behavior_hideable="false"
    app:behavior_peekHeight="@dimen/bottom_sheet_peek_height">

    <!-- RecyclerView? -->  
        <TextView android:layout_width="match_parent"
            android:layout_height="@dimen/bottom_sheet_peek_height"
            android:text="Bottom sheet header" />

        <-- N heavy equally sized child views here -->

</androidx.core.widget.NestedScrollView>

I have read that RecyclerView outperforms ListView. Still, it seems to never recycle its views given the above configuration.

Camellia
  • 141
  • 14
l33t
  • 18,692
  • 16
  • 103
  • 180
  • did you try a single RecyclerView with multiple view types? – jaychang0917 Oct 02 '18 at 03:40
  • No, I will try that. But even with that solution, it will keep inflating/drawing all views, right? My biggest concern is that the `RecyclerView` immediately draws all its children when shown. The scrolling seems to work quite well in `androidx:1.0.0`. – l33t Oct 02 '18 at 07:57
  • all the children are inflated and drawn as your RecyclerView is nested inside a NestedScrollView. A RecyclerView with multiple types is enough. – jaychang0917 Oct 02 '18 at 12:40
  • did u find any solution @l33t – shadow Jun 01 '20 at 10:39
  • I used a `ViewStub` in the end, inflating the views when expanding the bottom sheet the first time. Will improve on it in the future. So far all other attempts failed. – l33t Jun 01 '20 at 11:14

0 Answers0