I know similar questions have been asked multiple times, but the usual answer is simply use .inflate(R.layout.some_layout, parent, false)
. In my case, where the RecyclerView is nested within a ViewPager2 in combination with a TabLayout, the suggested solution does fill the width but then seems to lead to a fixed height for the recycler, which is not what i want.
Here is the current result, followed by the target:
Is there a solution that will not lead to me having to compromise on either filling the width XOR the height?
Here is the main layout which includes the viewpager and tabLayout, whose child is the recyclerview in question:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent">
<View
android:id="@+id/vBgMask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/core_sheet_mask" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/core_sheet_default_margin_horizontal"
android:layout_marginTop="@dimen/core_sheet_default_margin_top">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/layoutContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="@drawable/core_bg_bottom_sheet"
android:orientation="vertical"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<ImageView
android:id="@+id/btnClose"
style="@style/BtnClose"
android:layout_marginTop="@dimen/core_btnClose_marginTop"
android:contentDescription="@null" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="none"
android:layout_marginHorizontal="@dimen/core_margin_screenHorizontal"
android:layout_marginTop="6dp"
android:layout_weight="1">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tvIncidentTitle"
style="@style/Text.H4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
tools:text="Title of Incident" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tlIncidentInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="@color/quantum_white_100"
app:tabGravity="start"
app:tabMinWidth="60dp"
app:tabMode="fixed"
app:tabPaddingBottom="16dp"
app:tabPaddingEnd="16dp"
app:tabPaddingStart="16dp"
app:tabPaddingTop="16dp"
app:tabRippleColor="@null"
app:tabTextAppearance="@style/Text.Tab" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/vpIncidentDetails"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingTop="24dp"
android:layout_marginBottom="42dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/Text.Sub1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/core_description"
android:textColor="@color/core_dark60" />
<TextView
android:id="@+id/tvIncidentDesc"
style="@style/Text.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="@color/core_textOverline"
tools:text="Description of Incident" />
<TextView
android:id="@+id/tvMeasuresHeader"
style="@style/Text.Sub1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/flightplan_incident_view_measures"
android:textColor="@color/core_dark60"
android:visibility="visible" />
<TextView
android:id="@+id/tvMeasures"
style="@style/Text.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="@color/core_textOverline"
android:visibility="visible"
tools:text="Measures for incident hazard" />
<TextView
android:id="@+id/tvConsequencesHeader"
style="@style/Text.Sub1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/flightplan_incident_view_consequences"
android:textColor="@color/core_dark60"
android:visibility="visible" />
<TextView
android:id="@+id/tvConsequences"
style="@style/Text.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="@color/core_textOverline"
android:visibility="visible"
tools:text="Consequences of incident hazard" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</FrameLayout>
Here is the “Activity” tab’s layout which is basically the recyclerview in question:
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvItems"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="@dimen/core_margin_s"
android:orientation="vertical"
android:nestedScrollingEnabled="false"
android:background="@android:color/holo_blue_light"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" />
and here is the layout of one of the items (the one containing a cardview in the images):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:baselineAligned="false"
android:background="@android:color/holo_red_light"
android:orientation="horizontal">
<include
android:id="@+id/lTimeline"
layout="@layout/timeline_node_layout" />
<LinearLayout
android:id="@+id/llContent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="24dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tvActivityFollowUpStatusTitle"
style="@style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_regular"
tools:text="dd-mm-yyyy, hh:mm follow up added by Username" />
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:background="@color/quantum_white_100"
android:padding="12dp"
app:cardCornerRadius="16dp"
app:strokeColor="@color/core_dark10"
app:strokeWidth="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tvFollowUp"
style="@style/Text.Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:fontFamily="@font/poppins_regular"
android:textSize="14sp"
tools:text="I'm baby hexagon +1 lumbersexual ascot hammock distillery. Hammock umami taxidermy, ethical affogato disrupt dreamcatcher salvia hella jean shorts bicycle rights bruh banh mi. " />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvDocuments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12dp"
android:nestedScrollingEnabled="false"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</LinearLayout>