Android: RecyclerView inside ScrollView (or parallax)

I have a fragment with 2 maps with several controls inside.

Below is the second view of the map I have recyclerview , this works fine .

the problem is that recyclerview starts at the very bottom of the screen , and the scrolling of recyccerview is very small .

previously used listview, and this allowed me to match your content and thus make it possible to scroll across the screen right away, but with recylclerview it cannot.

How to do, when I look through recyclerview, controls increase as a parallax effect?

EDIT: more clearly, imagine 2 types of cards in a fragment, they occupy 80% of the screen, above them is a recyclerview with a list of 100 items, but the scroll is so tiny ... the list allows me to adapt to the "content" and scroll the entire screen at the same time.

this is my xml layout:

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/svScroll" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <include android:id="@+id/cvCampos1" layout="@layout/ctlcabeceralibreta" /> <include android:id="@+id/cvCampos2" layout="@layout/ctlcabeceralibreta2" /> <android.support.v7.widget.RecyclerView android:id="@+id/rvRegistros" android:layout_width="fill_parent" android:layout_height="1000dp" android:layout_below="@id/cvCampos2" android:scrollbars="vertical" /> </RelativeLayout> </ScrollView> 

this is a screenshot:

enter image description here

+6
source share
2 answers

In the above case, you need to use multiple ViewHolders in the same recyclerview .

I see that you have three types of layouts. The first two maps and other layouts in your recyclerview .

RecyclerView with several types of views gives you an example of using several types of views in a simple recyclerview utility.

+2
source

fixed height setting works !!! but I need to calculate the height the number of elements in the list

this works for listviews (I have not tested it with recyclerview)

 public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return; } int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom(); for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); if (listItem instanceof ViewGroup) { listItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); } 

Src:

Full example

0
source

Source: https://habr.com/ru/post/981288/


All Articles