0

I've seen other answers to this question but none worked for me; for example the top answer here (How to get the height of recyclerview item in "onBindViewHolder") says to do this:

view.measure(
             View.MeasureSpec.makeMeasureSpec(recyclerViewWidth, View.MeasureSpec.EXACTLY),
             View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

but then doing view.getMeasuredHeight() only returns whatever I pass in for recyclerViewWidth.

Basically I want to set the size of components within the recycler view cell as fractions of the cell's size, but those fractions depend on the position of the cell. I'm a bit frustrated since this is so simple to do in iOS and seems so much more convoluted in android.

49529485
  • 37
  • 4

1 Answers1

0

I am not a fan of setting percentages by code on Android. And if you do want to set your view's sizes relative to its parent, ContraintLayout are your best friend for setting items based on percentage guidelines, barriers, and ratios are something you should look into, it is efficient and you do not have to worry about calculation yourself.

https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout