質問編集履歴
9
質問内容が削除されていたので元に戻す変更を行いました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
スクロールする
|
1
|
+
RecyclerViewが勝手にスクロールする
|
test
CHANGED
@@ -1,25 +1,495 @@
|
|
1
1
|
###前提・実現したいこと
|
2
2
|
|
3
|
+
RecyclerViewを用いた画面を作成しています。
|
4
|
+
|
5
|
+
スワイプで画面を切り替えると自動でスクロールしてしまいます。
|
6
|
+
|
7
|
+
なぜ勝手にスクロールしてしまうのか理由がわかりません。
|
8
|
+
|
9
|
+
そもそもこのようなレイアウトは不可能なのでしょうか。
|
10
|
+
|
11
|
+
###発生している問題・エラーメッセージ
|
12
|
+
|
13
|
+
RecyclerView - View - RecyclerViewという順で
|
14
|
+
|
15
|
+
LinearLayoutのVerticalで配置しています。
|
16
|
+
|
17
|
+
真ん中のViewが表示される位置までスクロールした状態で、
|
18
|
+
|
19
|
+
スワイプで画面を切り替え、元に戻ると、
|
20
|
+
|
21
|
+
下部のRecyclerViewの上端がレイアウトのトップの位置に
|
22
|
+
|
3
23
|
自動でスクロールしてしまいます。
|
4
24
|
|
5
|
-
|
6
|
-
|
7
|
-
###発生している問題・エラーメッセージ
|
8
|
-
|
9
|
-
|
10
|
-
|
11
25
|
```
|
12
26
|
|
13
27
|
エラーメッセージは特にありません。
|
14
28
|
|
15
29
|
```
|
16
30
|
|
17
|
-
|
31
|
+
起動直後
|
32
|
+
|
33
|
+
![イメージ説明](9f8fa0b0fc231d24911ed1d19c518bce.png)
|
34
|
+
|
35
|
+
真ん中のViewが表示される位置までスクロール
|
36
|
+
|
37
|
+
![イメージ説明](22339a26ad4b5e678a7595417c7a1215.png)
|
38
|
+
|
39
|
+
スワイプで画面切り替え
|
40
|
+
|
41
|
+
![イメージ説明](346765fb73e3b636c52eb8e145da9f7f.png)
|
42
|
+
|
43
|
+
元のページに戻り中
|
44
|
+
|
45
|
+
![イメージ説明](c11f7fecdfe4be36d97e36b5a2501d07.png)
|
46
|
+
|
47
|
+
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
48
|
+
|
49
|
+
![イメージ説明](3d11b9af5fd1c91cae08cbe95e39d138.png)
|
50
|
+
|
51
|
+
###該当のソースコード
|
52
|
+
|
53
|
+
activity_main.xml
|
54
|
+
|
55
|
+
```xml
|
56
|
+
|
57
|
+
<?xml version="1.0" encoding="utf-8"?>
|
58
|
+
|
59
|
+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
60
|
+
|
61
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
62
|
+
|
63
|
+
android:layout_width="match_parent"
|
64
|
+
|
65
|
+
android:layout_height="match_parent">
|
66
|
+
|
67
|
+
<android.support.design.widget.AppBarLayout
|
68
|
+
|
69
|
+
android:layout_width="match_parent"
|
70
|
+
|
71
|
+
android:layout_height="wrap_content">
|
72
|
+
|
73
|
+
<android.support.v7.widget.Toolbar
|
74
|
+
|
75
|
+
android:id="@+id/toolbar"
|
76
|
+
|
77
|
+
android:layout_width="match_parent"
|
78
|
+
|
79
|
+
android:layout_height="?attr/actionBarSize"
|
80
|
+
|
81
|
+
android:background="?attr/colorPrimary"
|
82
|
+
|
83
|
+
app:layout_scrollFlags="scroll|enterAlways" />
|
84
|
+
|
85
|
+
<android.support.design.widget.TabLayout
|
86
|
+
|
87
|
+
android:id="@+id/tab_layout"
|
88
|
+
|
89
|
+
android:layout_width="match_parent"
|
90
|
+
|
91
|
+
android:layout_height="wrap_content"
|
92
|
+
|
93
|
+
android:background="?attr/colorPrimary"
|
94
|
+
|
95
|
+
app:tabIndicatorColor="#FFFF8D" />
|
96
|
+
|
97
|
+
</android.support.design.widget.AppBarLayout>
|
98
|
+
|
99
|
+
<android.support.v4.view.ViewPager
|
100
|
+
|
101
|
+
android:id="@+id/view_pager"
|
102
|
+
|
103
|
+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
104
|
+
|
105
|
+
android:layout_width="match_parent"
|
106
|
+
|
107
|
+
android:layout_height="wrap_content"/>
|
108
|
+
|
109
|
+
</android.support.design.widget.CoordinatorLayout>
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
MainActivity.java
|
114
|
+
|
115
|
+
```java
|
116
|
+
|
117
|
+
public class MainActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
|
118
|
+
|
119
|
+
@Override
|
120
|
+
|
121
|
+
protected void onCreate(Bundle savedInstanceState) {
|
122
|
+
|
123
|
+
super.onCreate(savedInstanceState);
|
124
|
+
|
125
|
+
setContentView(R.layout.activity_main);
|
126
|
+
|
127
|
+
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
128
|
+
|
129
|
+
setSupportActionBar(toolbar);
|
130
|
+
|
131
|
+
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
|
132
|
+
|
133
|
+
@Override
|
134
|
+
|
135
|
+
public Fragment getItem(int position) {
|
136
|
+
|
137
|
+
return BlankFragment.newInstance("", "");
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
@Override
|
142
|
+
|
143
|
+
public CharSequence getPageTitle(int position) {
|
144
|
+
|
145
|
+
return "tab " + (position + 1);
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
@Override
|
150
|
+
|
151
|
+
public int getCount() {
|
152
|
+
|
153
|
+
return 2;
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
};
|
158
|
+
|
159
|
+
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
|
160
|
+
|
161
|
+
viewPager.setAdapter(adapter);
|
162
|
+
|
163
|
+
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
164
|
+
|
165
|
+
tabLayout.setupWithViewPager(viewPager);
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
@Override
|
170
|
+
|
171
|
+
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
@Override
|
176
|
+
|
177
|
+
public void onPageSelected(int position) {
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
@Override
|
182
|
+
|
183
|
+
public void onPageScrollStateChanged(int state) {
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
RecyclerAdapter.java
|
192
|
+
|
193
|
+
```java
|
194
|
+
|
195
|
+
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
|
196
|
+
|
197
|
+
private LayoutInflater mInflater;
|
198
|
+
|
199
|
+
private ArrayList<String> mData;
|
200
|
+
|
201
|
+
public RecyclerAdapter(Context context, ArrayList<String> data) {
|
202
|
+
|
203
|
+
mInflater = LayoutInflater.from(context);
|
204
|
+
|
205
|
+
mData = data;
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
@Override
|
210
|
+
|
211
|
+
public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
212
|
+
|
213
|
+
return new ViewHolder(mInflater.inflate(R.layout.list_item, viewGroup, false));
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
@Override
|
218
|
+
|
219
|
+
public void onBindViewHolder(ViewHolder viewHolder, final int i) {
|
220
|
+
|
221
|
+
if (mData != null && mData.size() > i && mData.get(i) != null) {
|
222
|
+
|
223
|
+
viewHolder.textView.setText(mData.get(i));
|
224
|
+
|
225
|
+
if (i % 2 == 0) {
|
226
|
+
|
227
|
+
viewHolder.textView.setBackgroundColor(Color.argb(0x44, 0xff, 0x00, 0x00));
|
228
|
+
|
229
|
+
} else {
|
230
|
+
|
231
|
+
viewHolder.textView.setBackgroundColor(Color.argb(0x44, 0x00, 0x00, 0xff));
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
@Override
|
240
|
+
|
241
|
+
public int getItemCount() {
|
242
|
+
|
243
|
+
if (mData != null) {
|
244
|
+
|
245
|
+
return mData.size();
|
246
|
+
|
247
|
+
} else {
|
248
|
+
|
249
|
+
return 0;
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
class ViewHolder extends RecyclerView.ViewHolder {
|
256
|
+
|
257
|
+
TextView textView;
|
258
|
+
|
259
|
+
public ViewHolder(View itemView) {
|
260
|
+
|
261
|
+
super(itemView);
|
262
|
+
|
263
|
+
textView = (TextView) itemView.findViewById(R.id.list_item_text);
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
```
|
272
|
+
|
273
|
+
BlankFragment.java
|
274
|
+
|
275
|
+
```java
|
276
|
+
|
277
|
+
public class BlankFragment extends Fragment {
|
278
|
+
|
279
|
+
private static final String ARG_PARAM1 = "param1";
|
280
|
+
|
281
|
+
private static final String ARG_PARAM2 = "param2";
|
282
|
+
|
283
|
+
private String mParam1;
|
284
|
+
|
285
|
+
private String mParam2;
|
286
|
+
|
287
|
+
private View mRootView;
|
288
|
+
|
289
|
+
public BlankFragment() {
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
public static BlankFragment newInstance(String param1, String param2) {
|
294
|
+
|
295
|
+
BlankFragment fragment = new BlankFragment();
|
296
|
+
|
297
|
+
Bundle args = new Bundle();
|
298
|
+
|
299
|
+
args.putString(ARG_PARAM1, param1);
|
300
|
+
|
301
|
+
args.putString(ARG_PARAM2, param2);
|
302
|
+
|
303
|
+
fragment.setArguments(args);
|
304
|
+
|
305
|
+
return fragment;
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
@Override
|
310
|
+
|
311
|
+
public void onCreate(Bundle savedInstanceState) {
|
312
|
+
|
313
|
+
super.onCreate(savedInstanceState);
|
314
|
+
|
315
|
+
if (getArguments() != null) {
|
316
|
+
|
317
|
+
mParam1 = getArguments().getString(ARG_PARAM1);
|
318
|
+
|
319
|
+
mParam2 = getArguments().getString(ARG_PARAM2);
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
@Override
|
326
|
+
|
327
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
328
|
+
|
329
|
+
Bundle savedInstanceState) {
|
330
|
+
|
331
|
+
mRootView = inflater.inflate(R.layout.fragment_blank, container, false);
|
332
|
+
|
333
|
+
return mRootView;
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
@Override
|
338
|
+
|
339
|
+
public void onAttach(Context context) {
|
340
|
+
|
341
|
+
super.onAttach(context);
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
@Override
|
346
|
+
|
347
|
+
public void onDetach() {
|
348
|
+
|
349
|
+
super.onDetach();
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
@Override
|
354
|
+
|
355
|
+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
356
|
+
|
357
|
+
super.onActivityCreated(savedInstanceState);
|
358
|
+
|
359
|
+
ArrayList<String> upperArray = new ArrayList<>();
|
360
|
+
|
361
|
+
for (Integer i=0; i<10; i++) {
|
362
|
+
|
363
|
+
upperArray.add("upper " + i.toString());
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
RecyclerAdapter upperAdapter = new RecyclerAdapter(getActivity(), upperArray);
|
368
|
+
|
369
|
+
RecyclerView mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.upper_recycler_view);
|
370
|
+
|
371
|
+
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
372
|
+
|
373
|
+
mRecyclerView.setAdapter(upperAdapter);
|
374
|
+
|
375
|
+
ArrayList<String> lowerArray = new ArrayList<>();
|
376
|
+
|
377
|
+
for (Integer i=0; i<10; i++) {
|
378
|
+
|
379
|
+
lowerArray.add("lower " + i.toString());
|
380
|
+
|
381
|
+
}
|
382
|
+
|
383
|
+
RecyclerAdapter lowerAdapter = new RecyclerAdapter(getActivity(), lowerArray);
|
384
|
+
|
385
|
+
RecyclerView mRecyclerView2 = (RecyclerView) mRootView.findViewById(R.id.lower_recycler_view);
|
386
|
+
|
387
|
+
mRecyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
|
388
|
+
|
389
|
+
mRecyclerView2.setAdapter(lowerAdapter);
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
```
|
396
|
+
|
397
|
+
fragment_blank.xml
|
398
|
+
|
399
|
+
```xml
|
400
|
+
|
401
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
402
|
+
|
403
|
+
android:orientation="vertical"
|
404
|
+
|
405
|
+
android:layout_width="match_parent"
|
406
|
+
|
407
|
+
android:layout_height="match_parent" >
|
408
|
+
|
409
|
+
<android.support.v4.widget.NestedScrollView
|
410
|
+
|
411
|
+
android:layout_width="match_parent"
|
412
|
+
|
413
|
+
android:layout_height="match_parent">
|
414
|
+
|
415
|
+
<LinearLayout
|
416
|
+
|
417
|
+
android:orientation="vertical"
|
418
|
+
|
419
|
+
android:layout_width="match_parent"
|
420
|
+
|
421
|
+
android:layout_height="match_parent">
|
422
|
+
|
423
|
+
<android.support.v7.widget.RecyclerView
|
424
|
+
|
425
|
+
android:id="@+id/upper_recycler_view"
|
426
|
+
|
427
|
+
android:layout_width="match_parent"
|
428
|
+
|
429
|
+
android:layout_height="wrap_content" />
|
430
|
+
|
431
|
+
<View
|
432
|
+
|
433
|
+
android:background="#ff00ff00"
|
434
|
+
|
435
|
+
android:layout_width="match_parent"
|
436
|
+
|
437
|
+
android:layout_height="200dp" />
|
438
|
+
|
439
|
+
<android.support.v7.widget.RecyclerView
|
440
|
+
|
441
|
+
android:id="@+id/lower_recycler_view"
|
442
|
+
|
443
|
+
android:layout_width="match_parent"
|
444
|
+
|
445
|
+
android:layout_height="wrap_content" />
|
446
|
+
|
447
|
+
</LinearLayout>
|
448
|
+
|
449
|
+
</android.support.v4.widget.NestedScrollView>
|
450
|
+
|
451
|
+
</LinearLayout>
|
452
|
+
|
453
|
+
```
|
454
|
+
|
455
|
+
build.gradleのdependencies
|
456
|
+
|
457
|
+
```gradle
|
458
|
+
|
459
|
+
dependencies {
|
460
|
+
|
461
|
+
compile fileTree(dir: 'libs', include: ['*.jar'])
|
462
|
+
|
463
|
+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
464
|
+
|
465
|
+
exclude group: 'com.android.support', module: 'support-annotations'
|
466
|
+
|
467
|
+
})
|
468
|
+
|
469
|
+
compile 'com.android.support:appcompat-v7:24.2.1'
|
470
|
+
|
471
|
+
compile 'com.android.support:design:24.2.1'
|
472
|
+
|
473
|
+
compile 'com.android.support:support-v4:24.2.1'
|
474
|
+
|
475
|
+
compile 'com.android.support:recyclerview-v7:24.2.1'
|
476
|
+
|
477
|
+
testCompile 'junit:junit:4.12'
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
```
|
18
482
|
|
19
483
|
###試したこと
|
20
484
|
|
485
|
+
真ん中のViewが表示されない位置で試すと再現しない
|
486
|
+
|
21
487
|
エミュレータでも試してみましたが同様の結果でした。
|
22
488
|
|
23
|
-
|
24
|
-
|
25
489
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
490
|
+
|
491
|
+
端末: xperia z1
|
492
|
+
|
493
|
+
OS: Android 4.4.2
|
494
|
+
|
495
|
+
開発環境: Android studio 2.2.2
|
8
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
スクロールする
|
test
CHANGED
File without changes
|
7
説明を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,28 +1,10 @@
|
|
1
1
|
###前提・実現したいこと
|
2
2
|
|
3
|
-
RecyclerViewを用いた画面を作成しています。
|
4
|
-
|
5
|
-
|
3
|
+
自動でスクロールしてしまいます。
|
6
|
-
|
7
|
-
なぜ勝手にスクロールしてしまうのか理由がわかりません。
|
8
|
-
|
9
|
-
そもそもこのようなレイアウトは不可能なのでしょうか。
|
10
4
|
|
11
5
|
|
12
6
|
|
13
7
|
###発生している問題・エラーメッセージ
|
14
|
-
|
15
|
-
RecyclerView - View - RecyclerViewという順で
|
16
|
-
|
17
|
-
LinearLayoutのVerticalで配置しています。
|
18
|
-
|
19
|
-
真ん中のViewが表示される位置までスクロールした状態で、
|
20
|
-
|
21
|
-
スワイプで画面を切り替え、元に戻ると、
|
22
|
-
|
23
|
-
下部のRecyclerViewの上端がレイアウトのトップの位置に
|
24
|
-
|
25
|
-
自動でスクロールしてしまいます。
|
26
8
|
|
27
9
|
|
28
10
|
|
@@ -36,16 +18,8 @@
|
|
36
18
|
|
37
19
|
###試したこと
|
38
20
|
|
39
|
-
真ん中のViewが表示されない位置で試すと再現しない
|
40
|
-
|
41
21
|
エミュレータでも試してみましたが同様の結果でした。
|
42
22
|
|
43
23
|
|
44
24
|
|
45
25
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
46
|
-
|
47
|
-
端末: xperia z1
|
48
|
-
|
49
|
-
OS: Android 4.4.2
|
50
|
-
|
51
|
-
開発環境: Android studio 2.2.2
|
6
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
勝手にスクロールする
|
test
CHANGED
File without changes
|
5
画像とソースコードを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,566 +34,6 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
起動直後
|
38
|
-
|
39
|
-
![イメージ説明](9f8fa0b0fc231d24911ed1d19c518bce.png)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
真ん中のViewが表示される位置までスクロール
|
44
|
-
|
45
|
-
![イメージ説明](22339a26ad4b5e678a7595417c7a1215.png)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
スワイプで画面切り替え
|
50
|
-
|
51
|
-
![イメージ説明](346765fb73e3b636c52eb8e145da9f7f.png)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
元のページに戻り中
|
56
|
-
|
57
|
-
![イメージ説明](c11f7fecdfe4be36d97e36b5a2501d07.png)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
62
|
-
|
63
|
-
![イメージ説明](3d11b9af5fd1c91cae08cbe95e39d138.png)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
###該当のソースコード
|
68
|
-
|
69
|
-
activity_main.xml
|
70
|
-
|
71
|
-
```xml
|
72
|
-
|
73
|
-
<?xml version="1.0" encoding="utf-8"?>
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
78
|
-
|
79
|
-
xmlns:app="http://schemas.android.com/apk/res-auto"
|
80
|
-
|
81
|
-
android:layout_width="match_parent"
|
82
|
-
|
83
|
-
android:layout_height="match_parent">
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
<android.support.design.widget.AppBarLayout
|
88
|
-
|
89
|
-
android:layout_width="match_parent"
|
90
|
-
|
91
|
-
android:layout_height="wrap_content">
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
<android.support.v7.widget.Toolbar
|
96
|
-
|
97
|
-
android:id="@+id/toolbar"
|
98
|
-
|
99
|
-
android:layout_width="match_parent"
|
100
|
-
|
101
|
-
android:layout_height="?attr/actionBarSize"
|
102
|
-
|
103
|
-
android:background="?attr/colorPrimary"
|
104
|
-
|
105
|
-
app:layout_scrollFlags="scroll|enterAlways" />
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
<android.support.design.widget.TabLayout
|
110
|
-
|
111
|
-
android:id="@+id/tab_layout"
|
112
|
-
|
113
|
-
android:layout_width="match_parent"
|
114
|
-
|
115
|
-
android:layout_height="wrap_content"
|
116
|
-
|
117
|
-
android:background="?attr/colorPrimary"
|
118
|
-
|
119
|
-
app:tabIndicatorColor="#FFFF8D" />
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
</android.support.design.widget.AppBarLayout>
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
<android.support.v4.view.ViewPager
|
128
|
-
|
129
|
-
android:id="@+id/view_pager"
|
130
|
-
|
131
|
-
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
132
|
-
|
133
|
-
android:layout_width="match_parent"
|
134
|
-
|
135
|
-
android:layout_height="wrap_content"/>
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
</android.support.design.widget.CoordinatorLayout>
|
140
|
-
|
141
|
-
```
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
MainActivity.java
|
146
|
-
|
147
|
-
```java
|
148
|
-
|
149
|
-
public class MainActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
@Override
|
154
|
-
|
155
|
-
protected void onCreate(Bundle savedInstanceState) {
|
156
|
-
|
157
|
-
super.onCreate(savedInstanceState);
|
158
|
-
|
159
|
-
setContentView(R.layout.activity_main);
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
164
|
-
|
165
|
-
setSupportActionBar(toolbar);
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
|
170
|
-
|
171
|
-
@Override
|
172
|
-
|
173
|
-
public Fragment getItem(int position) {
|
174
|
-
|
175
|
-
return BlankFragment.newInstance("", "");
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
@Override
|
182
|
-
|
183
|
-
public CharSequence getPageTitle(int position) {
|
184
|
-
|
185
|
-
return "tab " + (position + 1);
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
@Override
|
192
|
-
|
193
|
-
public int getCount() {
|
194
|
-
|
195
|
-
return 2;
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
};
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
|
204
|
-
|
205
|
-
viewPager.setAdapter(adapter);
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
210
|
-
|
211
|
-
tabLayout.setupWithViewPager(viewPager);
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
@Override
|
218
|
-
|
219
|
-
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@Override
|
226
|
-
|
227
|
-
public void onPageSelected(int position) {
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
@Override
|
234
|
-
|
235
|
-
public void onPageScrollStateChanged(int state) {
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
```
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
RecyclerAdapter.java
|
246
|
-
|
247
|
-
```java
|
248
|
-
|
249
|
-
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
private LayoutInflater mInflater;
|
254
|
-
|
255
|
-
private ArrayList<String> mData;
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
public RecyclerAdapter(Context context, ArrayList<String> data) {
|
260
|
-
|
261
|
-
mInflater = LayoutInflater.from(context);
|
262
|
-
|
263
|
-
mData = data;
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
@Override
|
270
|
-
|
271
|
-
public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
272
|
-
|
273
|
-
return new ViewHolder(mInflater.inflate(R.layout.list_item, viewGroup, false));
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
@Override
|
280
|
-
|
281
|
-
public void onBindViewHolder(ViewHolder viewHolder, final int i) {
|
282
|
-
|
283
|
-
if (mData != null && mData.size() > i && mData.get(i) != null) {
|
284
|
-
|
285
|
-
viewHolder.textView.setText(mData.get(i));
|
286
|
-
|
287
|
-
if (i % 2 == 0) {
|
288
|
-
|
289
|
-
viewHolder.textView.setBackgroundColor(Color.argb(0x44, 0xff, 0x00, 0x00));
|
290
|
-
|
291
|
-
} else {
|
292
|
-
|
293
|
-
viewHolder.textView.setBackgroundColor(Color.argb(0x44, 0x00, 0x00, 0xff));
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
@Override
|
304
|
-
|
305
|
-
public int getItemCount() {
|
306
|
-
|
307
|
-
if (mData != null) {
|
308
|
-
|
309
|
-
return mData.size();
|
310
|
-
|
311
|
-
} else {
|
312
|
-
|
313
|
-
return 0;
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
class ViewHolder extends RecyclerView.ViewHolder {
|
322
|
-
|
323
|
-
TextView textView;
|
324
|
-
|
325
|
-
public ViewHolder(View itemView) {
|
326
|
-
|
327
|
-
super(itemView);
|
328
|
-
|
329
|
-
textView = (TextView) itemView.findViewById(R.id.list_item_text);
|
330
|
-
|
331
|
-
}
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
```
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
BlankFragment.java
|
342
|
-
|
343
|
-
```java
|
344
|
-
|
345
|
-
public class BlankFragment extends Fragment {
|
346
|
-
|
347
|
-
private static final String ARG_PARAM1 = "param1";
|
348
|
-
|
349
|
-
private static final String ARG_PARAM2 = "param2";
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
private String mParam1;
|
354
|
-
|
355
|
-
private String mParam2;
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
private View mRootView;
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
public BlankFragment() {
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
public static BlankFragment newInstance(String param1, String param2) {
|
370
|
-
|
371
|
-
BlankFragment fragment = new BlankFragment();
|
372
|
-
|
373
|
-
Bundle args = new Bundle();
|
374
|
-
|
375
|
-
args.putString(ARG_PARAM1, param1);
|
376
|
-
|
377
|
-
args.putString(ARG_PARAM2, param2);
|
378
|
-
|
379
|
-
fragment.setArguments(args);
|
380
|
-
|
381
|
-
return fragment;
|
382
|
-
|
383
|
-
}
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
@Override
|
388
|
-
|
389
|
-
public void onCreate(Bundle savedInstanceState) {
|
390
|
-
|
391
|
-
super.onCreate(savedInstanceState);
|
392
|
-
|
393
|
-
if (getArguments() != null) {
|
394
|
-
|
395
|
-
mParam1 = getArguments().getString(ARG_PARAM1);
|
396
|
-
|
397
|
-
mParam2 = getArguments().getString(ARG_PARAM2);
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
}
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
@Override
|
406
|
-
|
407
|
-
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
408
|
-
|
409
|
-
Bundle savedInstanceState) {
|
410
|
-
|
411
|
-
mRootView = inflater.inflate(R.layout.fragment_blank, container, false);
|
412
|
-
|
413
|
-
return mRootView;
|
414
|
-
|
415
|
-
}
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
@Override
|
420
|
-
|
421
|
-
public void onAttach(Context context) {
|
422
|
-
|
423
|
-
super.onAttach(context);
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
@Override
|
430
|
-
|
431
|
-
public void onDetach() {
|
432
|
-
|
433
|
-
super.onDetach();
|
434
|
-
|
435
|
-
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
@Override
|
440
|
-
|
441
|
-
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
442
|
-
|
443
|
-
super.onActivityCreated(savedInstanceState);
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
ArrayList<String> upperArray = new ArrayList<>();
|
448
|
-
|
449
|
-
for (Integer i=0; i<10; i++) {
|
450
|
-
|
451
|
-
upperArray.add("upper " + i.toString());
|
452
|
-
|
453
|
-
}
|
454
|
-
|
455
|
-
RecyclerAdapter upperAdapter = new RecyclerAdapter(getActivity(), upperArray);
|
456
|
-
|
457
|
-
RecyclerView mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.upper_recycler_view);
|
458
|
-
|
459
|
-
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
460
|
-
|
461
|
-
mRecyclerView.setAdapter(upperAdapter);
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
ArrayList<String> lowerArray = new ArrayList<>();
|
468
|
-
|
469
|
-
for (Integer i=0; i<10; i++) {
|
470
|
-
|
471
|
-
lowerArray.add("lower " + i.toString());
|
472
|
-
|
473
|
-
}
|
474
|
-
|
475
|
-
RecyclerAdapter lowerAdapter = new RecyclerAdapter(getActivity(), lowerArray);
|
476
|
-
|
477
|
-
RecyclerView mRecyclerView2 = (RecyclerView) mRootView.findViewById(R.id.lower_recycler_view);
|
478
|
-
|
479
|
-
mRecyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
|
480
|
-
|
481
|
-
mRecyclerView2.setAdapter(lowerAdapter);
|
482
|
-
|
483
|
-
}
|
484
|
-
|
485
|
-
}
|
486
|
-
|
487
|
-
```
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
fragment_blank.xml
|
492
|
-
|
493
|
-
```xml
|
494
|
-
|
495
|
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
496
|
-
|
497
|
-
android:orientation="vertical"
|
498
|
-
|
499
|
-
android:layout_width="match_parent"
|
500
|
-
|
501
|
-
android:layout_height="match_parent" >
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
<android.support.v4.widget.NestedScrollView
|
506
|
-
|
507
|
-
android:layout_width="match_parent"
|
508
|
-
|
509
|
-
android:layout_height="match_parent">
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
<LinearLayout
|
514
|
-
|
515
|
-
android:orientation="vertical"
|
516
|
-
|
517
|
-
android:layout_width="match_parent"
|
518
|
-
|
519
|
-
android:layout_height="match_parent">
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
<android.support.v7.widget.RecyclerView
|
524
|
-
|
525
|
-
android:id="@+id/upper_recycler_view"
|
526
|
-
|
527
|
-
android:layout_width="match_parent"
|
528
|
-
|
529
|
-
android:layout_height="wrap_content" />
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
<View
|
534
|
-
|
535
|
-
android:background="#ff00ff00"
|
536
|
-
|
537
|
-
android:layout_width="match_parent"
|
538
|
-
|
539
|
-
android:layout_height="200dp" />
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
<android.support.v7.widget.RecyclerView
|
544
|
-
|
545
|
-
android:id="@+id/lower_recycler_view"
|
546
|
-
|
547
|
-
android:layout_width="match_parent"
|
548
|
-
|
549
|
-
android:layout_height="wrap_content" />
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
</LinearLayout>
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
</android.support.v4.widget.NestedScrollView>
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
</LinearLayout>
|
562
|
-
|
563
|
-
```
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
build.gradleのdependencies
|
568
|
-
|
569
|
-
```gradle
|
570
|
-
|
571
|
-
dependencies {
|
572
|
-
|
573
|
-
compile fileTree(dir: 'libs', include: ['*.jar'])
|
574
|
-
|
575
|
-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
576
|
-
|
577
|
-
exclude group: 'com.android.support', module: 'support-annotations'
|
578
|
-
|
579
|
-
})
|
580
|
-
|
581
|
-
compile 'com.android.support:appcompat-v7:24.2.1'
|
582
|
-
|
583
|
-
compile 'com.android.support:design:24.2.1'
|
584
|
-
|
585
|
-
compile 'com.android.support:support-v4:24.2.1'
|
586
|
-
|
587
|
-
compile 'com.android.support:recyclerview-v7:24.2.1'
|
588
|
-
|
589
|
-
testCompile 'junit:junit:4.12'
|
590
|
-
|
591
|
-
}
|
592
|
-
|
593
|
-
```
|
594
|
-
|
595
|
-
|
596
|
-
|
597
37
|
###試したこと
|
598
38
|
|
599
39
|
真ん中のViewが表示されない位置で試すと再現しない
|
4
最後の画像がToolbarが表示されているものだったので、バグ発生直後の表示されていないものに更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
62
62
|
|
63
|
-
![イメージ説明](a5
|
63
|
+
![イメージ説明](3d11b9af5fd1c91cae08cbe95e39d138.png)
|
64
64
|
|
65
65
|
|
66
66
|
|
3
BlankFragmentでfindViewIdしている箇所をgetActivity\(\)からmRootViewに変更、画像も更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,13 +48,13 @@
|
|
48
48
|
|
49
49
|
スワイプで画面切り替え
|
50
50
|
|
51
|
-
![イメージ説明](4
|
51
|
+
![イメージ説明](346765fb73e3b636c52eb8e145da9f7f.png)
|
52
52
|
|
53
53
|
|
54
54
|
|
55
55
|
元のページに戻り中
|
56
56
|
|
57
|
-
![イメージ説明](7e
|
57
|
+
![イメージ説明](c11f7fecdfe4be36d97e36b5a2501d07.png)
|
58
58
|
|
59
59
|
|
60
60
|
|
@@ -356,6 +356,10 @@
|
|
356
356
|
|
357
357
|
|
358
358
|
|
359
|
+
private View mRootView;
|
360
|
+
|
361
|
+
|
362
|
+
|
359
363
|
public BlankFragment() {
|
360
364
|
|
361
365
|
}
|
@@ -404,7 +408,9 @@
|
|
404
408
|
|
405
409
|
Bundle savedInstanceState) {
|
406
410
|
|
407
|
-
|
411
|
+
mRootView = inflater.inflate(R.layout.fragment_blank, container, false);
|
412
|
+
|
413
|
+
return mRootView;
|
408
414
|
|
409
415
|
}
|
410
416
|
|
@@ -448,7 +454,7 @@
|
|
448
454
|
|
449
455
|
RecyclerAdapter upperAdapter = new RecyclerAdapter(getActivity(), upperArray);
|
450
456
|
|
451
|
-
RecyclerView mRecyclerView = (RecyclerView)
|
457
|
+
RecyclerView mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.upper_recycler_view);
|
452
458
|
|
453
459
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
454
460
|
|
@@ -468,7 +474,7 @@
|
|
468
474
|
|
469
475
|
RecyclerAdapter lowerAdapter = new RecyclerAdapter(getActivity(), lowerArray);
|
470
476
|
|
471
|
-
RecyclerView mRecyclerView2 = (RecyclerView)
|
477
|
+
RecyclerView mRecyclerView2 = (RecyclerView) mRootView.findViewById(R.id.lower_recycler_view);
|
472
478
|
|
473
479
|
mRecyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
|
474
480
|
|
2
説明画像を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,7 +52,13 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
-
元のページに戻
|
55
|
+
元のページに戻り中
|
56
|
+
|
57
|
+
![イメージ説明](7e9506953fcf4e2b480ba359e7df0595.png)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
56
62
|
|
57
63
|
![イメージ説明](a52a98df97c61465c5462067784aecd1.png)
|
58
64
|
|
1
エミュレータでも試した旨追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -586,6 +586,8 @@
|
|
586
586
|
|
587
587
|
真ん中のViewが表示されない位置で試すと再現しない
|
588
588
|
|
589
|
+
エミュレータでも試してみましたが同様の結果でした。
|
590
|
+
|
589
591
|
|
590
592
|
|
591
593
|
###補足情報(言語/FW/ツール等のバージョンなど)
|