Last active
December 7, 2018 20:17
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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