1

I have layout which includes some button, textviews and a recyclerview.

The layout already has a scrollView, so i disabled scroll of recyclerView.

Now i want to set the height of recyclerView programatically.

This is what i am doing right now.

    int totalItems= cardsRecyclerAdapter.getItemCount();

    ViewGroup.LayoutParams params=rvCards.getLayoutParams();
    params.height=200*totalItems;
    rvCards.setLayoutParams(params);

Here i am hardcoding 200 for testing, and its working fine, but i am using wrap_content for image height, and image height can be of any length, so i want to calculate the height the right way.

Is there any way to get the actual height of recycler view?

dev90
  • 7,187
  • 15
  • 80
  • 153
  • 1
    Convert it to pixel : https://stackoverflow.com/questions/5255184/android-and-setting-width-and-height-programmatically-in-dp-units – aslamhossin Dec 19 '18 at 12:14
  • @AslamHossin : Thanks, but i need to know how to get the actual height of recyclerAdapter, without hard coding any number. – dev90 Dec 19 '18 at 12:18
  • Create e custom RecyclerView and override the onMeasure Method . Check my answer below. – aslamhossin Dec 19 '18 at 12:26

0 Answers0