Bismillaahirrohmaanirrohiim…
Saat menggunakan dua atau lebih recyclerview dalam satu halaman, kemungkinan besar data item dari recyclerview tidak ditampilkan semua jika isinya banyak.
Namun hal ini terjadi pada HP android versi 8 (Oreo) ke atas. Untuk versi Nougat masih aman.
Contoh kodenya seperti berikut
<ScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:layout_marginBottom="50dp" android:fillViewport="true" android:scrollbars="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f4f4f4" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_satu" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f4f4f4" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_dua" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </LinearLayout> </LinearLayout> </ScrollView>
Agar bisa berjalan sesuai harapan, dimana semua item di dalam recyclerview bisa tampil, maka
– scrollview harus dirubah menjadi NestedScrollView
– menambahkan setNestedScrollingEnabled(false) di code java recyclerview
Hasilnya menjadi seperti di bawah ini:
<android.support.v4.widget.NestedScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:layout_marginBottom="50dp" android:fillViewport="true" android:scrollbars="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f4f4f4" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_satu" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f4f4f4" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_dua" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </LinearLayout> </LinearLayout> </android.support.v4.widget.NestedScrollView>
di code javanya:
rv_satu = (RecyclerView) view.findViewById(R.id.rv_satu); GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3); rv_satu.setLayoutManager(gridLayoutManager); rv_satu.setItemAnimator(new DefaultItemAnimator()); rv_satu.setNestedScrollingEnabled(false); rv_dua = (RecyclerView) view.findViewById(R.id.rv_dua); GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3); rv_dua.setLayoutManager(gridLayoutManager); rv_dua.setItemAnimator(new DefaultItemAnimator()); rv_dua.setNestedScrollingEnabled(false);
Taraa… sudah keluar semua itemnya.
Semoga bermanfaat.
Bismillaahirrohmaanirrohiim... Berikut ini beberapa template blogspot yang dapat anda gunakan secara gratis namun tampilannya bagus.…
Bismillaahirrohmaanirrohiim... Bagi yang menggunakan xampp, mungkin sudah familiar dengan database mysql dan web base phpmyadmin.…
Bismillaahirrohmaanirrohiim... Bagi pengguna server linux, adakalanya kena serangan hacker, dimana servernya digunakan untuk menjalankan aksi…
Bismillaahirrohmaanirrohiim... Saat kita membuat kotak dengan lebar dan tinggi tertentu, tentunya teks didalamnya harus kita…
Bismillaahirrohmaanirrohiim... Clearfix pada css biasanya digunakan untuk menangani posisi elemen saat menggunakan float, dimana float…
Bismillaahirrohmaanirrohiim... Setelah menginstall node.js dan ingin menggunakan perintah npx atau npm di power shell atau…