Skip to content

Instantly share code, notes, and snippets.

@sumanabhi
Last active December 7, 2018 20:17
Show Gist options
  • Save sumanabhi/63a010b9ae7fddceec60a533d002e3fc to your computer and use it in GitHub Desktop.
Save sumanabhi/63a010b9ae7fddceec60a533d002e3fc to your computer and use it in GitHub Desktop.
This helps to make the RecyclerView height at runtime based on their child.
package com.animus.app.CustomViews;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.ViewGroup;
/**
* Created by app on 23/11/17.
*/
public class NonScrollRecyclerView extends RecyclerView {
public NonScrollRecyclerView(Context context) {
super(context);
}
public NonScrollRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment