Created
December 3, 2015 20:57
-
-
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
This file contains 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
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).