But its not working.
Try to set height like this,
ViewGroup.LayoutParams params=recyclerview.getLayoutParams(); params.height=100; recyclerview.setLayoutParams(params);
Came across same question just now and although ajantha’s solution works, I found a more simpler solution. If this still helps, great, glad to pay it forward.
recyclerView.getLayoutParams().height = 100;
Well, it’s too late but I have a better solution.
recyclerView.getLayoutParams().height will give you
null pointer when you create a new
recycler view programmatically. Here is a proper way of doing it.
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); recyclerView.setLayoutParams(params);
Keep in mind that the first param is
width while the second is