1
1
# StickLayout [ ![ Download] ( https://api.bintray.com/packages/wkp/maven/StickLayout/images/download.svg ) ] ( https://bintray.com/wkp/maven/StickLayout/_latestVersion )
2
- 粘性控件,其任意一个子控件都可滑动停留,无论是View,还是ViewGroup.
2
+ 粘性控件,其任意一个子控件都可滑动停留,无论是View,还是ViewGroup;用该控件可以轻松实现支付宝"全部应用"界面。
3
3
## 演示图
4
4
![ DragGridView] ( https://github.com/wkp111/StickLayout/blob/master/StickLayout.gif " 演示图 ")
5
+ ![ DragGridView] ( https://github.com/wkp111/StickLayout/blob/master/StickLayout1.gif " 演示图1 ") <br />
6
+ Note:图1为设置属性wkp_canScrollToEndViewTop=true,图2没有。
5
7
## Gradle集成
6
8
``` groovy
7
9
dependencies{
8
- compile 'com.wkp:StickLayout:1.0.1 '
10
+ compile 'com.wkp:StickLayout:1.0.3 '
9
11
//Android Studio3.0+可用以下方式
10
- //implementation 'com.wkp:StickLayout:1.0.1 '
12
+ //implementation 'com.wkp:StickLayout:1.0.3 '
11
13
}
12
14
```
13
15
Note:可能存在Jcenter还在审核阶段,这时会集成失败!
14
16
## 使用详解
15
17
> 属性讲解
16
18
``` xml
17
- <!-- 是否粘性停留-->
19
+ <!-- 是否粘性停留(用于直接子控件) -->
18
20
<attr name =" wkp_stick" format =" boolean" />
21
+ <!-- 是否开启滑动到最后一个控件的顶部,默认不开启(用于控件本身)-->
22
+ <attr name =" wkp_canScrollToEndViewTop" format =" boolean" />
19
23
```
20
24
Note:每个属性都有对应的java设置代码!
21
25
> 布局
@@ -38,6 +42,7 @@ Note:每个属性都有对应的java设置代码!
38
42
android : layout_width =" match_parent"
39
43
android : layout_height =" wrap_content" />
40
44
45
+ <!-- app:wkp_canScrollToEndViewTop="true"-->
41
46
<com .wkp.sticklayout_lib.widget.StickLayout
42
47
android : id =" @+id/sl"
43
48
android : layout_width =" match_parent"
@@ -58,32 +63,36 @@ Note:每个属性都有对应的java设置代码!
58
63
android : layout_height =" 40dp" >
59
64
60
65
<TextView
61
- android : background =" @android:color/holo_green_light"
62
- android : text =" NUM1"
66
+ android : onClick =" scrollTo"
67
+ android : background =" @android:color/holo_blue_light"
68
+ android : text =" NUM2"
63
69
android : gravity =" center"
64
70
android : layout_weight =" 1"
65
71
android : layout_width =" 0dp"
66
72
android : layout_height =" match_parent" />
67
73
68
74
<TextView
69
- android : background =" @android:color/holo_blue_light"
70
- android : text =" NUM2"
75
+ android : onClick =" scrollTo3"
76
+ android : background =" @android:color/holo_green_light"
77
+ android : text =" NUM3"
71
78
android : gravity =" center"
72
79
android : layout_weight =" 1"
73
80
android : layout_width =" 0dp"
74
81
android : layout_height =" match_parent" />
75
82
76
83
<TextView
84
+ android : onClick =" scrollTo4"
77
85
android : background =" @android:color/holo_red_light"
78
- android : text =" NUM3 "
86
+ android : text =" NUM4 "
79
87
android : gravity =" center"
80
88
android : layout_weight =" 1"
81
89
android : layout_width =" 0dp"
82
90
android : layout_height =" match_parent" />
83
91
84
92
<TextView
93
+ android : onClick =" scrollTo7"
85
94
android : background =" @android:color/holo_orange_light"
86
- android : text =" NUM4 "
95
+ android : text =" NUM7 "
87
96
android : gravity =" center"
88
97
android : layout_weight =" 1"
89
98
android : layout_width =" 0dp"
@@ -109,6 +118,7 @@ Note:每个属性都有对应的java设置代码!
109
118
android : layout_height =" 200dp" />
110
119
111
120
<TextView
121
+ android : background =" @android:color/holo_red_light"
112
122
android : id =" @+id/tv4"
113
123
android : text =" 第4行"
114
124
android : gravity =" center"
@@ -130,6 +140,7 @@ Note:每个属性都有对应的java设置代码!
130
140
android : layout_height =" 200dp" />
131
141
132
142
<TextView
143
+ android : background =" @android:color/holo_orange_light"
133
144
android : id =" @+id/tv7"
134
145
android : text =" 第7行"
135
146
android : gravity =" center"
@@ -147,14 +158,23 @@ Note:ScrollView嵌套StickLayout时事件被拦截,无效果!
147
158
public class MainActivity extends AppCompatActivity {
148
159
149
160
private StickLayout mSl;
161
+ private TextView mTv2;
162
+ private View mTv3;
163
+ private View mTv7;
164
+ private View mTv4;
150
165
151
166
@Override
152
167
protected void onCreate (Bundle savedInstanceState ) {
153
168
super . onCreate(savedInstanceState);
154
169
setContentView(R . layout. activity_main);
155
170
mSl = findViewById(R . id. sl);
171
+ mTv2 = findViewById(R . id. tv2);
172
+ mTv3 = findViewById(R . id. tv3);
173
+ mTv4 = findViewById(R . id. tv4);
174
+ mTv7 = findViewById(R . id. tv7);
156
175
// mSl.setStickView(findViewById(R.id.tv2));
157
176
// mSl.setStickView(findViewById(R.id.tv3));
177
+ // mSl.canScrollToEndViewTop(true);
158
178
}
159
179
160
180
public void addView (View view ) {
@@ -168,7 +188,25 @@ public class MainActivity extends AppCompatActivity {
168
188
public void click (View view ) {
169
189
Toast . makeText(this , " 第1行" , Toast . LENGTH_SHORT ). show();
170
190
}
191
+
192
+ public void scrollTo (View view ) {
193
+ // 滑动到指定子控件
194
+ mSl. scrollToView(mTv2);
195
+ }
196
+
197
+ public void scrollTo3 (View view ) {
198
+ mSl. scrollToView(mTv3);
199
+ }
200
+
201
+ public void scrollTo4 (View view ) {
202
+ mSl. scrollToView(mTv4);
203
+ }
204
+
205
+ public void scrollTo7 (View view ) {
206
+ mSl. scrollToView(mTv7);
207
+ }
171
208
}
209
+
172
210
```
173
211
Note:还有其他API请根据需要自行参考!
174
212
## 寄语
180
218
181
219
182
220
## 版本更新
221
+ * v1.0.3<br />
222
+ 新增滑动到指定子控件API<br /><br />
183
223
* v1.0.1<br />
184
224
新创建子可粘性停留控件库
185
225
## License
0 commit comments