У меня есть такая структура (XML):
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/bottom_style"
android:scrollIndicators="none"
app:behavior_hideable="false"
app:behavior_peekHeight="@dimen/peek_height"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="18dp"
android:paddingTop="6dp"
android:paddingEnd="18dp"
android:paddingBottom="6dp">
<androidx.recyclerview.widget.RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="20dp"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Поэтому я устанавливаю адаптер и настраиваю RecyclerView:
recyclerView.setAdapter(new MyRecyclerAdapter(context, myList));
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
recyclerView.setNestedScrollingEnabled(false);
/**Creates a ViewPager-like behavior**/
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
А в MyRecyclerAdapter представление динамически заполняется для каждого RecyclerView элемента, и мы получаем различную высоту для каждого элемента.
Проблема заключается в том, что общая высота RecyclerView определяется первым элементом, и все последующие элементы, высота которых больше этой, обрезаются (я бы даже сказал, уменьшаются) на этапе их создания.
Вот как это выглядит:



Как это можно исправить?
решено:
Я добавил код, который вычисляет и устанавливает новый размер после того, как элемент View был динамически заполнен ( viewHolder.parent it recyclerView ):
int newHeight = 0;
View itemView = viewHolder.itemView;
itemView.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
newHeight += itemView.getMeasuredHeight();
newHeight += DpToPx(8+15);
newHeight += 1;
LinearLayout.LayoutParams llParams = (LinearLayout.LayoutParams) viewHolder.parent.getLayoutParams();
llParams.height = newHeight;
viewHolder.parent.setLayoutParams(llParams);
Read м руда здесь: { ссылка }