Skip to content

Instantly share code, notes, and snippets.

@AlexKGwyn
Created December 3, 2015 20:57
Show Gist options
  • Save AlexKGwyn/c9cbae3b737aa6db8d90 to your computer and use it in GitHub Desktop.
Save AlexKGwyn/c9cbae3b737aa6db8d90 to your computer and use it in GitHub Desktop.
A LinearLayoutManager that measures children to be the same size as their RecyclerView parent
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.util.AttributeSet;
import android.view.View;
public class FullScreenLinearLayoutManager extends LinearLayoutManager {
public FullScreenLinearLayoutManager(Context context) {
super(context);
}
public FullScreenLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public FullScreenLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void measureChildWithMargins(View child, int widthUsed, int heightUsed) {
measureChild(child, widthUsed, heightUsed);
}
@Override
public void measureChild(View child, int widthUsed, int heightUsed) {
int widthmeasureSpec = View.MeasureSpec.makeMeasureSpec(getWidth(), View.MeasureSpec.EXACTLY);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(getHeight(), View.MeasureSpec.EXACTLY);
child.measure(widthmeasureSpec, heightMeasureSpec);
}
}
@PaulWoitaschek
Copy link

PaulWoitaschek commented May 14, 2018

Thanks. However there is a reason why there is a measureChild and a measureChildWithMargins (and that is that the measureChildWithMargins takes the marings into account).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment