i\'m trying to set the height of recycler view on wrap_content and make it respect that,but it will exceed the other widget on layout. what can i do now?
<
I had this issue. I needed to build a UI page that contained a RecyclerView
with an unknown number of elements that should scroll. The page had the the following layout:
LinearLayout
ConstraintLayout
TextView
RecyclerView
TextView
and I wanted heights to be determined procedurally for everything using match_parent
and wrap_content
.
I wanted the RecyclerView
to use all the space available between the two TextViews
.
The key was to give the RecyclerView
an "impossible" constraint, by doing this:
app:layout_constraintTop_toBottomOf="@+id/topTextView"
app:layout_constraintBottom_toTopOf="@+id/bottomTextView"
and adding this:
app:layout_constrainedHeight="true"
If you need to add margin between the top TextView
and RecyclerView
(and/or the bottom TextView
and RecyclerView
) put the margin on the RecyclerView
, not the TextViews
.
Code Examples
Below is the actual code I'm using (with some text styling removed for readability)
As a final note, the HolderView
also uses only wrap_content
. Here's that code as well: