LayoutManagers.java
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.naji.xiaotao.widget;
import android.support.annotation.IntDef;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public class LayoutManagers {
protected LayoutManagers() {
}
public interface LayoutManagerFactory {
RecyclerView.LayoutManager create(RecyclerView recyclerView);
}
/**
* A {@link LinearLayoutManager}.
*/
public static LayoutManagerFactory linear() {
return new LayoutManagerFactory() {
@Override
public RecyclerView.LayoutManager create(RecyclerView recyclerView) {
return new FullyLinearLayoutManager(recyclerView.getContext());
}
};
}
/**
* A {@link LinearLayoutManager} with the given orientation and reverseLayout.
*/
public static LayoutManagerFactory linear(@LayoutManagers.Orientation final int orientation, final boolean reverseLayout) {
return new LayoutManagerFactory() {
@Override
public RecyclerView.LayoutManager create(RecyclerView recyclerView) {
return new LinearLayoutManager(recyclerView.getContext(), orientation, reverseLayout);
}
};
}
/**
* A {@link GridLayoutManager} with the given spanCount.
*/
public static LayoutManagerFactory grid(final int spanCount) {
return new LayoutManagers.LayoutManagerFactory() {
@Override
public RecyclerView.LayoutManager create(RecyclerView recyclerView) {
return new GridLayoutManager(recyclerView.getContext(), spanCount);
}
};
}
/**
* A {@link GridLayoutManager} with the given spanCount, orientation and reverseLayout.
**/
public static LayoutManagers.LayoutManagerFactory grid(final int spanCount, @LayoutManagers.Orientation final int orientation, final boolean reverseLayout) {
return new LayoutManagers.LayoutManagerFactory() {
@Override
public RecyclerView.LayoutManager create(RecyclerView recyclerView) {
return new GridLayoutManager(recyclerView.getContext(), spanCount, orientation, reverseLayout);
}
};
}
/**
* A {@link StaggeredGridLayoutManager} with the given spanCount and orientation.
*/
public static LayoutManagers.LayoutManagerFactory staggeredGrid(final int spanCount, @LayoutManagers.Orientation final int orientation) {
return new LayoutManagers.LayoutManagerFactory() {
@Override
public RecyclerView.LayoutManager create(RecyclerView recyclerView) {
return new StaggeredGridLayoutManager(spanCount, orientation);
}
};
}
@IntDef({LinearLayoutManager.HORIZONTAL, LinearLayoutManager.VERTICAL})
@Retention(RetentionPolicy.SOURCE)
public @interface Orientation {
}
}