Cheer Up
总结&记录
LiveTemplate for RecyclerView Adapter
1 | Settings | Editor | File and Code Templates |
添加模板文件,命名为 RecyclerView Adapter
1 | #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end |
NdkOptions - abiFilters1
2
3
4
5
6
7
8
9
10
11android {
// Similar to other properties in the defaultConfig block, you can override
// these properties for each product flavor in your build configuration.
defaultConfig {
ndk {
// Tells Gradle to build outputs for the following ABIs and package
// them into your APK.
abiFilters 'x86', 'x86_64', 'armeabi'
}
}
}
另外一种方式1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16productFlavors {
flavor1 {
ndk {
abiFilters "armeabi-v7a"
}
}
flavor2 {
ndk {
abiFilters "armeabi-v7a"
abiFilters "x86"
abiFilters "armeabi"
abiFilters "arm64-v8a"
abiFilters "x86_64"
}
}
}
在 android studio 安装目录找到文件夹:{Android Studio installation dir}\plugins\android\lib\templates\other
依次创建以下文件:
template.xml
1 | <template |
recipe.xml.ftl
1 | <?xml version="1.0"?> |
globals.xml.ftl
1 | <?xml version="1.0"?> |
root/src/app_package/Contract.java.ftl
1 | package ${packageName}; |
root/src/app_package/Model.java.ftl
1 | package ${packageName}; |
root/src/app_package/Presenster.java.ftl
1 |
|
root/src/app_package/Bean.java.ftl
1 | package ${packageName}; |
创建完成后,重新启动 android studio,就可使用新建向导了。
美团打包
project build.gradle1
2
3
4
5
6
7
8
9
10
11
12
13
14buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // add plugin
classpath 'com.meituan.android.walle:plugin:1.1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
app/build.gradle1
2
3
4
5
6
7
8
9compile 'com.meituan.android.walle:library:1.1.5' 依赖库
walle {
// 指定渠道包的输出路径
apkOutputFolder = new File("${project.buildDir}/outputs/channels");
// 定制渠道包的APK的文件名称
apkFileNameFormat = 'youle_v${versionName}_${channel}_${buildType}_${buildTime}.apk';
// 渠道配置文件
configFile = new File("${project.getProjectDir()}/config.json")
}
app/config.json1
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277{
"channelInfoList": [
{
"channel": "caiyi",
"alias": "采邑",
"extraInfo": {
"aliChannel": "701172"
}
},
{
"channel": "yingyongbao",
"alias": "应用宝",
"extraInfo": {
"aliChannel": "10005890"
}
},
{
"channel": "_360",
"alias": "360",
"extraInfo": {
"aliChannel": "10005884"
}
},
{
"channel": "baidu",
"alias": "百度",
"extraInfo": {
"aliChannel": "10005882"
}
},
{
"channel": "xiaomi",
"alias": "小米",
"extraInfo": {
"aliChannel": "700159"
}
},
{
"channel": "huawei",
"alias": "华为",
"extraInfo": {
"aliChannel": "10002089"
}
},
{
"channel": "samsung",
"alias": "三星",
"extraInfo": {
"aliChannel": "600153"
}
},
{
"channel": "lenovo",
"alias": "联想",
"extraInfo": {
"aliChannel": "203200"
}
},
{
"channel": "meizu",
"alias": "魅族",
"extraInfo": {
"aliChannel": "702003"
}
},
{
"channel": "oppo",
"alias": "oppo",
"extraInfo": {
"aliChannel": "263200"
}
},
{
"channel": "vivo",
"alias": "vivo",
"extraInfo": {
"aliChannel": "10003993"
}
},
{
"channel": "leshi",
"alias": "乐视",
"extraInfo": {
"aliChannel": "10002912"
}
},
{
"channel": "alipp",
"alias": "阿里PP",
"extraInfo": {
"aliChannel": "10005894"
}
},
{
"channel": "yy001",
"alias": "yy001",
"extraInfo": {
"aliChannel": "10006813"
}
},
{
"channel": "yy002",
"alias": "yy002",
"extraInfo": {
"aliChannel": "10006814"
}
},
{
"channel": "yy003",
"alias": "yy003",
"extraInfo": {
"aliChannel": "10006815"
}
},
{
"channel": "yy004",
"alias": "yy004",
"extraInfo": {
"aliChannel": "10006816"
}
},
{
"channel": "yy005",
"alias": "yy005",
"extraInfo": {
"aliChannel": "10006817"
}
},
{
"channel": "yy006",
"alias": "yy006",
"extraInfo": {
"aliChannel": "10006818"
}
},
{
"channel": "yy007",
"alias": "yy007",
"extraInfo": {
"aliChannel": "10006819"
}
},
{
"channel": "yy008",
"alias": "yy008",
"extraInfo": {
"aliChannel": "10006820"
}
},
{
"channel": "yy009",
"alias": "yy009",
"extraInfo": {
"aliChannel": "10006821"
}
},
{
"channel": "yy010",
"alias": "yy010",
"extraInfo": {
"aliChannel": "10006822"
}
},
{
"channel": "yy011",
"alias": "yy011",
"extraInfo": {
"aliChannel": "10006823"
}
},
{
"channel": "yy012",
"alias": "yy012",
"extraInfo": {
"aliChannel": "10006824"
}
},
{
"channel": "yy013",
"alias": "yy013",
"extraInfo": {
"aliChannel": "10006825"
}
},
{
"channel": "yy014",
"alias": "yy014",
"extraInfo": {
"aliChannel": "10006826"
}
},
{
"channel": "yy015",
"alias": "yy015",
"extraInfo": {
"aliChannel": "10006827"
}
},
{
"channel": "julangdsp",
"alias": "julangdsp",
"extraInfo": {
"aliChannel": "10006796"
}
},
{
"channel": "100001",
"alias": "100001",
"extraInfo": {
"aliChannel": "10006874"
}
},
{
"channel": "100002",
"alias": "100002",
"extraInfo": {
"aliChannel": "10006875"
}
},
{
"channel": "100003",
"alias": "100003",
"extraInfo": {
"aliChannel": "10006876"
}
},
{
"channel": "100004",
"alias": "100004",
"extraInfo": {
"aliChannel": "10006877"
}
},
{
"channel": "100005",
"alias": "100005",
"extraInfo": {
"aliChannel": "10006878"
}
},
{
"channel": "100006",
"alias": "100006",
"extraInfo": {
"aliChannel": "10006879"
}
},
{
"channel": "100007",
"alias": "100007",
"extraInfo": {
"aliChannel": "10006880"
}
},
{
"channel": "100008",
"alias": "100008",
"extraInfo": {
"aliChannel": "10006881"
}
},
{
"channel": "100009",
"alias": "100009",
"extraInfo": {
"aliChannel": "10006882"
}
},
{
"channel": "100010",
"alias": "100010",
"extraInfo": {
"aliChannel": "10006883"
}
}
]
}
Positions in RecyclerView:
RecyclerView introduces an additional level of abstraction between the RecyclerView.Adapter and RecyclerView.LayoutManager to be able to detect data set changes in batches during a layout calculation(计算)
. This saves LayoutManager from tracking adapter changes to calculate animations. It also helps with performance because all view bindings happen at the same time and unnecessary bindings are avoided.
For this reason, there are two types of position related methods in RecyclerView:
These two positions are the same except the time between dispatching adapter.notify* events and calculating the updated layout.
Methods that return or receive LayoutPosition use position as of the latest layout calculation (e.g. getLayoutPosition(), findViewHolderForLayoutPosition(int)). These positions include all changes until the last layout calculation. You can rely on these positions to be consistent with what user is currently seeing on the screen. For example, if you have a list of items on the screen and user asks for the 5th element, you should use these methods as they’ll match what user is seeing.
The other set of position related methods are in the form of AdapterPosition. (e.g. getAdapterPosition(), findViewHolderForAdapterPosition(int)) You should use these methods when you need to work with up-to-date adapter positions even if they may not have been reflected to layout yet. For example, if you want to access the item in the adapter on a ViewHolder click, you should use getAdapterPosition(). Beware that these methods may not be able to calculate adapter positions if notifyDataSetChanged() has been called and new layout has not yet been calculated. For this reasons, you should carefully handle NO_POSITION or null results from these methods.
When writing a RecyclerView.LayoutManager you almost always want to use layout positions whereas when writing an RecyclerView.Adapter, you probably want to use adapter positions
1 |
|
lint-error-do-not-treat-position-as-fixed-only-use-immediately
recyclerview-adapter-lint-error-do-not-treat-position-as-fixed1
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@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
EffectData data = dataSets.get(position);
if (data.getCoverPic() == null) {
holder.idIndexItemImage.setImageResource(data.getImageID());
} else {
Glide.with(context)
.load(data.getCoverPic())
.placeholder(R.drawable.ic_filter1)
.into(holder.idIndexItemImage);
}
holder.idIndexItemText.setText(data.getText());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = holder.getAdapterPosition();
mOnItemClickListener.onItemClick(holder, pos);
select(pos);
}
});
if (data.isSelected()) {
holder.itemView.setSelected(true);
} else {
holder.itemView.setSelected(false);
}
}
A flexible view for providing a limited window into a large data set.
1 | java.lang.Object |
(与...截然不同的)
Position.(废料,小片,残余物)
(view): A child view that has entered into a temporarily detached state during layout. Scrap views may be reused without becoming fully detached from the parent RecyclerView, either unmodified if no rebinding is required or modified by the adapter if the view was considered dirty.(计算)
. This saves LayoutManager from tracking adapter changes to calculate animations. It also helps with performance because all view bindings happen at the same time and unnecessary bindings are avoided.For this reason, there are two types of position related methods in RecyclerView:
These two positions are the same except the time between dispatching adapter.notify* events and calculating the updated layout.
Methods that return or receive LayoutPosition use position as of the latest layout calculation (e.g. getLayoutPosition(), findViewHolderForLayoutPosition(int)). These positions include all changes until the last layout calculation. You can rely on these positions to be consistent with what user is currently seeing on the screen. For example, if you have a list of items on the screen and user asks for the 5th element, you should use these methods as they’ll match what user is seeing.
The other set of position related methods are in the form of AdapterPosition. (e.g. getAdapterPosition(), findViewHolderForAdapterPosition(int)) You should use these methods when you need to work with up-to-date adapter positions even if they may not have been reflected to layout yet. For example, if you want to access the item in the adapter on a ViewHolder click, you should use getAdapterPosition(). Beware that these methods may not be able to calculate adapter positions if notifyDataSetChanged() has been called and new layout has not yet been calculated. For this reasons, you should carefully handle NO_POSITION or null results from these methods.
When writing a RecyclerView.LayoutManager you almost always want to use layout positions whereas when writing an RecyclerView.Adapter, you probably want to use adapter positions.
1 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); |