-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Item decorator for similar margins in greed layout manager and ad…
…d examples
- Loading branch information
Max Rovkin
committed
Feb 12, 2015
1 parent
087759c
commit 1b323a1
Showing
7 changed files
with
117 additions
and
16 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<android.support.v7.widget.CardView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:card_view="http://schemas.android.com/apk/res-auto" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
card_view:cardCornerRadius="2dp" | ||
> | ||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="match_parent" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="2dp" | ||
android:gravity="center_vertical" | ||
android:layout_gravity="center" | ||
/> | ||
</LinearLayout> | ||
</android.support.v7.widget.CardView> |
82 changes: 82 additions & 0 deletions
82
paralaxheader/src/main/java/pro/useit/paralaxheader/SpacesItemDecoration.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package pro.useit.paralaxheader; | ||
|
||
import android.graphics.Rect; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
|
||
/** | ||
* Created UseIT for AdMe | ||
* User: maxrovkin | ||
* Date: 12.02.15 | ||
* Time: 14:31 | ||
*/ | ||
public class SpacesItemDecoration extends RecyclerView.ItemDecoration | ||
{ | ||
private int space; | ||
private int spanCount = 1; | ||
private boolean ignoreFirst = false; | ||
private int diffSize = 1; | ||
|
||
public SpacesItemDecoration(int space) | ||
{ | ||
this.space = space; | ||
} | ||
|
||
public SpacesItemDecoration(final int space, final int spanCount) | ||
{ | ||
this.space = space; | ||
this.spanCount = spanCount; | ||
} | ||
|
||
@Override | ||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) | ||
{ | ||
int targetPosition = parent.getChildPosition(view); | ||
if (ignoreFirst && targetPosition == 0) | ||
return; | ||
|
||
|
||
int positionInColumn = getPositionInColumn(targetPosition + diffSize); | ||
outRect.left = getLeftSpace(positionInColumn); | ||
outRect.right = getRightSpace(positionInColumn); | ||
|
||
//outRect.bottom = space; | ||
outRect.top = space; | ||
} | ||
|
||
public void setIgnoreFirst(final boolean ignoreFirst) | ||
{ | ||
this.ignoreFirst = ignoreFirst; | ||
diffSize = ignoreFirst ? 2 : 1; | ||
} | ||
|
||
private int getPositionInColumn(int targetPosition) | ||
{ | ||
int mod = targetPosition % spanCount; | ||
if (mod == 0) | ||
return spanCount; | ||
|
||
return mod; | ||
} | ||
|
||
private int getLeftSpace(int positionInColumn) | ||
{ | ||
if (positionInColumn == 1) | ||
return space; | ||
|
||
return space / 2; | ||
} | ||
|
||
private int getRightSpace(int positionInColumn) | ||
{ | ||
if (positionInColumn == spanCount) | ||
return space; | ||
|
||
return space / 2; | ||
} | ||
|
||
public void setSpanCount(final int spanCount) | ||
{ | ||
this.spanCount = spanCount; | ||
} | ||
} |