Last active
August 29, 2023 14:28
-
-
Save janheinrichmerker/39f9d2f9023a184d96f8 to your computer and use it in GitHub Desktop.
Revisions
-
janheinrichmerker revised this gist
Jul 29, 2020 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ MIT License Copyright (c) 2020 Jan Heinrich Reimer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -
janheinrichmerker created this gist
Jul 14, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ package de.wilhelmgym.quiz.recyclerview; import android.content.Context; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.view.ViewGroup; public class SpanningLinearLayoutManager extends LinearLayoutManager { public SpanningLinearLayoutManager(Context context) { super(context); } public SpanningLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { super(context, orientation, reverseLayout); } public SpanningLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override public RecyclerView.LayoutParams generateDefaultLayoutParams() { return spanLayoutSize(super.generateDefaultLayoutParams()); } @Override public RecyclerView.LayoutParams generateLayoutParams(Context c, AttributeSet attrs) { return spanLayoutSize(super.generateLayoutParams(c, attrs)); } @Override public RecyclerView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { return spanLayoutSize(super.generateLayoutParams(lp)); } @Override public boolean checkLayoutParams(RecyclerView.LayoutParams lp) { return super.checkLayoutParams(lp); } private RecyclerView.LayoutParams spanLayoutSize(RecyclerView.LayoutParams layoutParams){ if(getOrientation() == HORIZONTAL){ layoutParams.width = (int) Math.round(getHorizontalSpace() / (double) getItemCount()); } else if(getOrientation() == VERTICAL){ layoutParams.height = (int) Math.round(getVerticalSpace() / (double) getItemCount()); } return layoutParams; } @Override public boolean canScrollVertically() { return false; } @Override public boolean canScrollHorizontally() { return false; } private int getHorizontalSpace() { return getWidth() - getPaddingRight() - getPaddingLeft(); } private int getVerticalSpace() { return getHeight() - getPaddingBottom() - getPaddingTop(); } }