質問編集履歴
9
質問内容が削除されていたので元に戻す変更を行いました
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
スクロールする
|
1
|
+
RecyclerViewが勝手にスクロールする
|
body
CHANGED
@@ -1,13 +1,248 @@
|
|
1
1
|
###前提・実現したいこと
|
2
|
+
RecyclerViewを用いた画面を作成しています。
|
3
|
+
スワイプで画面を切り替えると自動でスクロールしてしまいます。
|
4
|
+
なぜ勝手にスクロールしてしまうのか理由がわかりません。
|
5
|
+
そもそもこのようなレイアウトは不可能なのでしょうか。
|
6
|
+
###発生している問題・エラーメッセージ
|
7
|
+
RecyclerView - View - RecyclerViewという順で
|
8
|
+
LinearLayoutのVerticalで配置しています。
|
9
|
+
真ん中のViewが表示される位置までスクロールした状態で、
|
10
|
+
スワイプで画面を切り替え、元に戻ると、
|
11
|
+
下部のRecyclerViewの上端がレイアウトのトップの位置に
|
2
12
|
自動でスクロールしてしまいます。
|
3
|
-
|
4
|
-
###発生している問題・エラーメッセージ
|
5
|
-
|
6
13
|
```
|
7
14
|
エラーメッセージは特にありません。
|
8
15
|
```
|
9
|
-
|
16
|
+
起動直後
|
17
|
+

|
18
|
+
真ん中のViewが表示される位置までスクロール
|
19
|
+

|
20
|
+
スワイプで画面切り替え
|
21
|
+

|
22
|
+
元のページに戻り中
|
23
|
+

|
24
|
+
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
25
|
+

|
26
|
+
###該当のソースコード
|
27
|
+
activity_main.xml
|
28
|
+
```xml
|
29
|
+
<?xml version="1.0" encoding="utf-8"?>
|
30
|
+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
31
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
32
|
+
android:layout_width="match_parent"
|
33
|
+
android:layout_height="match_parent">
|
34
|
+
<android.support.design.widget.AppBarLayout
|
35
|
+
android:layout_width="match_parent"
|
36
|
+
android:layout_height="wrap_content">
|
37
|
+
<android.support.v7.widget.Toolbar
|
38
|
+
android:id="@+id/toolbar"
|
39
|
+
android:layout_width="match_parent"
|
40
|
+
android:layout_height="?attr/actionBarSize"
|
41
|
+
android:background="?attr/colorPrimary"
|
42
|
+
app:layout_scrollFlags="scroll|enterAlways" />
|
43
|
+
<android.support.design.widget.TabLayout
|
44
|
+
android:id="@+id/tab_layout"
|
45
|
+
android:layout_width="match_parent"
|
46
|
+
android:layout_height="wrap_content"
|
47
|
+
android:background="?attr/colorPrimary"
|
48
|
+
app:tabIndicatorColor="#FFFF8D" />
|
49
|
+
</android.support.design.widget.AppBarLayout>
|
50
|
+
<android.support.v4.view.ViewPager
|
51
|
+
android:id="@+id/view_pager"
|
52
|
+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
53
|
+
android:layout_width="match_parent"
|
54
|
+
android:layout_height="wrap_content"/>
|
55
|
+
</android.support.design.widget.CoordinatorLayout>
|
56
|
+
```
|
57
|
+
MainActivity.java
|
58
|
+
```java
|
59
|
+
public class MainActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
|
60
|
+
@Override
|
61
|
+
protected void onCreate(Bundle savedInstanceState) {
|
62
|
+
super.onCreate(savedInstanceState);
|
63
|
+
setContentView(R.layout.activity_main);
|
64
|
+
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
65
|
+
setSupportActionBar(toolbar);
|
66
|
+
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
|
67
|
+
@Override
|
68
|
+
public Fragment getItem(int position) {
|
69
|
+
return BlankFragment.newInstance("", "");
|
70
|
+
}
|
71
|
+
@Override
|
72
|
+
public CharSequence getPageTitle(int position) {
|
73
|
+
return "tab " + (position + 1);
|
74
|
+
}
|
75
|
+
@Override
|
76
|
+
public int getCount() {
|
77
|
+
return 2;
|
78
|
+
}
|
79
|
+
};
|
80
|
+
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
|
81
|
+
viewPager.setAdapter(adapter);
|
82
|
+
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
83
|
+
tabLayout.setupWithViewPager(viewPager);
|
84
|
+
}
|
85
|
+
@Override
|
86
|
+
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
87
|
+
}
|
88
|
+
@Override
|
89
|
+
public void onPageSelected(int position) {
|
90
|
+
}
|
91
|
+
@Override
|
92
|
+
public void onPageScrollStateChanged(int state) {
|
93
|
+
}
|
94
|
+
}
|
95
|
+
```
|
96
|
+
RecyclerAdapter.java
|
97
|
+
```java
|
98
|
+
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
|
99
|
+
private LayoutInflater mInflater;
|
100
|
+
private ArrayList<String> mData;
|
101
|
+
public RecyclerAdapter(Context context, ArrayList<String> data) {
|
102
|
+
mInflater = LayoutInflater.from(context);
|
103
|
+
mData = data;
|
104
|
+
}
|
105
|
+
@Override
|
106
|
+
public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
107
|
+
return new ViewHolder(mInflater.inflate(R.layout.list_item, viewGroup, false));
|
108
|
+
}
|
109
|
+
@Override
|
110
|
+
public void onBindViewHolder(ViewHolder viewHolder, final int i) {
|
111
|
+
if (mData != null && mData.size() > i && mData.get(i) != null) {
|
112
|
+
viewHolder.textView.setText(mData.get(i));
|
113
|
+
if (i % 2 == 0) {
|
114
|
+
viewHolder.textView.setBackgroundColor(Color.argb(0x44, 0xff, 0x00, 0x00));
|
115
|
+
} else {
|
116
|
+
viewHolder.textView.setBackgroundColor(Color.argb(0x44, 0x00, 0x00, 0xff));
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
@Override
|
121
|
+
public int getItemCount() {
|
122
|
+
if (mData != null) {
|
123
|
+
return mData.size();
|
124
|
+
} else {
|
125
|
+
return 0;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
class ViewHolder extends RecyclerView.ViewHolder {
|
129
|
+
TextView textView;
|
130
|
+
public ViewHolder(View itemView) {
|
131
|
+
super(itemView);
|
132
|
+
textView = (TextView) itemView.findViewById(R.id.list_item_text);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
```
|
137
|
+
BlankFragment.java
|
138
|
+
```java
|
139
|
+
public class BlankFragment extends Fragment {
|
140
|
+
private static final String ARG_PARAM1 = "param1";
|
141
|
+
private static final String ARG_PARAM2 = "param2";
|
142
|
+
private String mParam1;
|
143
|
+
private String mParam2;
|
144
|
+
private View mRootView;
|
145
|
+
public BlankFragment() {
|
146
|
+
}
|
147
|
+
public static BlankFragment newInstance(String param1, String param2) {
|
148
|
+
BlankFragment fragment = new BlankFragment();
|
149
|
+
Bundle args = new Bundle();
|
150
|
+
args.putString(ARG_PARAM1, param1);
|
151
|
+
args.putString(ARG_PARAM2, param2);
|
152
|
+
fragment.setArguments(args);
|
153
|
+
return fragment;
|
154
|
+
}
|
155
|
+
@Override
|
156
|
+
public void onCreate(Bundle savedInstanceState) {
|
157
|
+
super.onCreate(savedInstanceState);
|
158
|
+
if (getArguments() != null) {
|
159
|
+
mParam1 = getArguments().getString(ARG_PARAM1);
|
160
|
+
mParam2 = getArguments().getString(ARG_PARAM2);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
@Override
|
164
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
165
|
+
Bundle savedInstanceState) {
|
166
|
+
mRootView = inflater.inflate(R.layout.fragment_blank, container, false);
|
167
|
+
return mRootView;
|
168
|
+
}
|
169
|
+
@Override
|
170
|
+
public void onAttach(Context context) {
|
171
|
+
super.onAttach(context);
|
172
|
+
}
|
173
|
+
@Override
|
174
|
+
public void onDetach() {
|
175
|
+
super.onDetach();
|
176
|
+
}
|
177
|
+
@Override
|
178
|
+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
179
|
+
super.onActivityCreated(savedInstanceState);
|
180
|
+
ArrayList<String> upperArray = new ArrayList<>();
|
181
|
+
for (Integer i=0; i<10; i++) {
|
182
|
+
upperArray.add("upper " + i.toString());
|
183
|
+
}
|
184
|
+
RecyclerAdapter upperAdapter = new RecyclerAdapter(getActivity(), upperArray);
|
185
|
+
RecyclerView mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.upper_recycler_view);
|
186
|
+
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
187
|
+
mRecyclerView.setAdapter(upperAdapter);
|
188
|
+
ArrayList<String> lowerArray = new ArrayList<>();
|
189
|
+
for (Integer i=0; i<10; i++) {
|
190
|
+
lowerArray.add("lower " + i.toString());
|
191
|
+
}
|
192
|
+
RecyclerAdapter lowerAdapter = new RecyclerAdapter(getActivity(), lowerArray);
|
193
|
+
RecyclerView mRecyclerView2 = (RecyclerView) mRootView.findViewById(R.id.lower_recycler_view);
|
194
|
+
mRecyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
|
195
|
+
mRecyclerView2.setAdapter(lowerAdapter);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
```
|
199
|
+
fragment_blank.xml
|
200
|
+
```xml
|
201
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
202
|
+
android:orientation="vertical"
|
203
|
+
android:layout_width="match_parent"
|
204
|
+
android:layout_height="match_parent" >
|
205
|
+
<android.support.v4.widget.NestedScrollView
|
206
|
+
android:layout_width="match_parent"
|
207
|
+
android:layout_height="match_parent">
|
208
|
+
<LinearLayout
|
209
|
+
android:orientation="vertical"
|
210
|
+
android:layout_width="match_parent"
|
211
|
+
android:layout_height="match_parent">
|
212
|
+
<android.support.v7.widget.RecyclerView
|
213
|
+
android:id="@+id/upper_recycler_view"
|
214
|
+
android:layout_width="match_parent"
|
215
|
+
android:layout_height="wrap_content" />
|
216
|
+
<View
|
217
|
+
android:background="#ff00ff00"
|
218
|
+
android:layout_width="match_parent"
|
219
|
+
android:layout_height="200dp" />
|
220
|
+
<android.support.v7.widget.RecyclerView
|
221
|
+
android:id="@+id/lower_recycler_view"
|
222
|
+
android:layout_width="match_parent"
|
223
|
+
android:layout_height="wrap_content" />
|
224
|
+
</LinearLayout>
|
225
|
+
</android.support.v4.widget.NestedScrollView>
|
226
|
+
</LinearLayout>
|
227
|
+
```
|
228
|
+
build.gradleのdependencies
|
229
|
+
```gradle
|
230
|
+
dependencies {
|
231
|
+
compile fileTree(dir: 'libs', include: ['*.jar'])
|
232
|
+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
233
|
+
exclude group: 'com.android.support', module: 'support-annotations'
|
234
|
+
})
|
235
|
+
compile 'com.android.support:appcompat-v7:24.2.1'
|
236
|
+
compile 'com.android.support:design:24.2.1'
|
237
|
+
compile 'com.android.support:support-v4:24.2.1'
|
238
|
+
compile 'com.android.support:recyclerview-v7:24.2.1'
|
239
|
+
testCompile 'junit:junit:4.12'
|
240
|
+
}
|
241
|
+
```
|
10
242
|
###試したこと
|
243
|
+
真ん中のViewが表示されない位置で試すと再現しない
|
11
244
|
エミュレータでも試してみましたが同様の結果でした。
|
12
|
-
|
13
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
245
|
+
###補足情報(言語/FW/ツール等のバージョンなど)
|
246
|
+
端末: xperia z1
|
247
|
+
OS: Android 4.4.2
|
248
|
+
開発環境: Android studio 2.2.2
|
8
タイトル変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
スクロールする
|
body
CHANGED
File without changes
|
7
説明を修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,26 +1,13 @@
|
|
1
1
|
###前提・実現したいこと
|
2
|
-
RecyclerViewを用いた画面を作成しています。
|
3
|
-
|
2
|
+
自動でスクロールしてしまいます。
|
4
|
-
なぜ勝手にスクロールしてしまうのか理由がわかりません。
|
5
|
-
そもそもこのようなレイアウトは不可能なのでしょうか。
|
6
3
|
|
7
4
|
###発生している問題・エラーメッセージ
|
8
|
-
RecyclerView - View - RecyclerViewという順で
|
9
|
-
LinearLayoutのVerticalで配置しています。
|
10
|
-
真ん中のViewが表示される位置までスクロールした状態で、
|
11
|
-
スワイプで画面を切り替え、元に戻ると、
|
12
|
-
下部のRecyclerViewの上端がレイアウトのトップの位置に
|
13
|
-
自動でスクロールしてしまいます。
|
14
5
|
|
15
6
|
```
|
16
7
|
エラーメッセージは特にありません。
|
17
8
|
```
|
18
9
|
|
19
10
|
###試したこと
|
20
|
-
真ん中のViewが表示されない位置で試すと再現しない
|
21
11
|
エミュレータでも試してみましたが同様の結果でした。
|
22
12
|
|
23
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
13
|
+
###補足情報(言語/FW/ツール等のバージョンなど)
|
24
|
-
端末: xperia z1
|
25
|
-
OS: Android 4.4.2
|
26
|
-
開発環境: Android studio 2.2.2
|
6
タイトル変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
勝手にスクロールする
|
body
CHANGED
File without changes
|
5
画像とソースコードを修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,286 +16,6 @@
|
|
16
16
|
エラーメッセージは特にありません。
|
17
17
|
```
|
18
18
|
|
19
|
-
起動直後
|
20
|
-

|
21
|
-
|
22
|
-
真ん中のViewが表示される位置までスクロール
|
23
|
-

|
24
|
-
|
25
|
-
スワイプで画面切り替え
|
26
|
-

|
27
|
-
|
28
|
-
元のページに戻り中
|
29
|
-

|
30
|
-
|
31
|
-
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
32
|
-

|
33
|
-
|
34
|
-
###該当のソースコード
|
35
|
-
activity_main.xml
|
36
|
-
```xml
|
37
|
-
<?xml version="1.0" encoding="utf-8"?>
|
38
|
-
|
39
|
-
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
40
|
-
xmlns:app="http://schemas.android.com/apk/res-auto"
|
41
|
-
android:layout_width="match_parent"
|
42
|
-
android:layout_height="match_parent">
|
43
|
-
|
44
|
-
<android.support.design.widget.AppBarLayout
|
45
|
-
android:layout_width="match_parent"
|
46
|
-
android:layout_height="wrap_content">
|
47
|
-
|
48
|
-
<android.support.v7.widget.Toolbar
|
49
|
-
android:id="@+id/toolbar"
|
50
|
-
android:layout_width="match_parent"
|
51
|
-
android:layout_height="?attr/actionBarSize"
|
52
|
-
android:background="?attr/colorPrimary"
|
53
|
-
app:layout_scrollFlags="scroll|enterAlways" />
|
54
|
-
|
55
|
-
<android.support.design.widget.TabLayout
|
56
|
-
android:id="@+id/tab_layout"
|
57
|
-
android:layout_width="match_parent"
|
58
|
-
android:layout_height="wrap_content"
|
59
|
-
android:background="?attr/colorPrimary"
|
60
|
-
app:tabIndicatorColor="#FFFF8D" />
|
61
|
-
|
62
|
-
</android.support.design.widget.AppBarLayout>
|
63
|
-
|
64
|
-
<android.support.v4.view.ViewPager
|
65
|
-
android:id="@+id/view_pager"
|
66
|
-
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
67
|
-
android:layout_width="match_parent"
|
68
|
-
android:layout_height="wrap_content"/>
|
69
|
-
|
70
|
-
</android.support.design.widget.CoordinatorLayout>
|
71
|
-
```
|
72
|
-
|
73
|
-
MainActivity.java
|
74
|
-
```java
|
75
|
-
public class MainActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
|
76
|
-
|
77
|
-
@Override
|
78
|
-
protected void onCreate(Bundle savedInstanceState) {
|
79
|
-
super.onCreate(savedInstanceState);
|
80
|
-
setContentView(R.layout.activity_main);
|
81
|
-
|
82
|
-
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
83
|
-
setSupportActionBar(toolbar);
|
84
|
-
|
85
|
-
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
|
86
|
-
@Override
|
87
|
-
public Fragment getItem(int position) {
|
88
|
-
return BlankFragment.newInstance("", "");
|
89
|
-
}
|
90
|
-
|
91
|
-
@Override
|
92
|
-
public CharSequence getPageTitle(int position) {
|
93
|
-
return "tab " + (position + 1);
|
94
|
-
}
|
95
|
-
|
96
|
-
@Override
|
97
|
-
public int getCount() {
|
98
|
-
return 2;
|
99
|
-
}
|
100
|
-
};
|
101
|
-
|
102
|
-
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
|
103
|
-
viewPager.setAdapter(adapter);
|
104
|
-
|
105
|
-
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
106
|
-
tabLayout.setupWithViewPager(viewPager);
|
107
|
-
}
|
108
|
-
|
109
|
-
@Override
|
110
|
-
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
111
|
-
}
|
112
|
-
|
113
|
-
@Override
|
114
|
-
public void onPageSelected(int position) {
|
115
|
-
}
|
116
|
-
|
117
|
-
@Override
|
118
|
-
public void onPageScrollStateChanged(int state) {
|
119
|
-
}
|
120
|
-
}
|
121
|
-
```
|
122
|
-
|
123
|
-
RecyclerAdapter.java
|
124
|
-
```java
|
125
|
-
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
|
126
|
-
|
127
|
-
private LayoutInflater mInflater;
|
128
|
-
private ArrayList<String> mData;
|
129
|
-
|
130
|
-
public RecyclerAdapter(Context context, ArrayList<String> data) {
|
131
|
-
mInflater = LayoutInflater.from(context);
|
132
|
-
mData = data;
|
133
|
-
}
|
134
|
-
|
135
|
-
@Override
|
136
|
-
public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
137
|
-
return new ViewHolder(mInflater.inflate(R.layout.list_item, viewGroup, false));
|
138
|
-
}
|
139
|
-
|
140
|
-
@Override
|
141
|
-
public void onBindViewHolder(ViewHolder viewHolder, final int i) {
|
142
|
-
if (mData != null && mData.size() > i && mData.get(i) != null) {
|
143
|
-
viewHolder.textView.setText(mData.get(i));
|
144
|
-
if (i % 2 == 0) {
|
145
|
-
viewHolder.textView.setBackgroundColor(Color.argb(0x44, 0xff, 0x00, 0x00));
|
146
|
-
} else {
|
147
|
-
viewHolder.textView.setBackgroundColor(Color.argb(0x44, 0x00, 0x00, 0xff));
|
148
|
-
}
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
@Override
|
153
|
-
public int getItemCount() {
|
154
|
-
if (mData != null) {
|
155
|
-
return mData.size();
|
156
|
-
} else {
|
157
|
-
return 0;
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
class ViewHolder extends RecyclerView.ViewHolder {
|
162
|
-
TextView textView;
|
163
|
-
public ViewHolder(View itemView) {
|
164
|
-
super(itemView);
|
165
|
-
textView = (TextView) itemView.findViewById(R.id.list_item_text);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
}
|
169
|
-
```
|
170
|
-
|
171
|
-
BlankFragment.java
|
172
|
-
```java
|
173
|
-
public class BlankFragment extends Fragment {
|
174
|
-
private static final String ARG_PARAM1 = "param1";
|
175
|
-
private static final String ARG_PARAM2 = "param2";
|
176
|
-
|
177
|
-
private String mParam1;
|
178
|
-
private String mParam2;
|
179
|
-
|
180
|
-
private View mRootView;
|
181
|
-
|
182
|
-
public BlankFragment() {
|
183
|
-
}
|
184
|
-
|
185
|
-
public static BlankFragment newInstance(String param1, String param2) {
|
186
|
-
BlankFragment fragment = new BlankFragment();
|
187
|
-
Bundle args = new Bundle();
|
188
|
-
args.putString(ARG_PARAM1, param1);
|
189
|
-
args.putString(ARG_PARAM2, param2);
|
190
|
-
fragment.setArguments(args);
|
191
|
-
return fragment;
|
192
|
-
}
|
193
|
-
|
194
|
-
@Override
|
195
|
-
public void onCreate(Bundle savedInstanceState) {
|
196
|
-
super.onCreate(savedInstanceState);
|
197
|
-
if (getArguments() != null) {
|
198
|
-
mParam1 = getArguments().getString(ARG_PARAM1);
|
199
|
-
mParam2 = getArguments().getString(ARG_PARAM2);
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
|
-
@Override
|
204
|
-
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
205
|
-
Bundle savedInstanceState) {
|
206
|
-
mRootView = inflater.inflate(R.layout.fragment_blank, container, false);
|
207
|
-
return mRootView;
|
208
|
-
}
|
209
|
-
|
210
|
-
@Override
|
211
|
-
public void onAttach(Context context) {
|
212
|
-
super.onAttach(context);
|
213
|
-
}
|
214
|
-
|
215
|
-
@Override
|
216
|
-
public void onDetach() {
|
217
|
-
super.onDetach();
|
218
|
-
}
|
219
|
-
|
220
|
-
@Override
|
221
|
-
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
222
|
-
super.onActivityCreated(savedInstanceState);
|
223
|
-
|
224
|
-
ArrayList<String> upperArray = new ArrayList<>();
|
225
|
-
for (Integer i=0; i<10; i++) {
|
226
|
-
upperArray.add("upper " + i.toString());
|
227
|
-
}
|
228
|
-
RecyclerAdapter upperAdapter = new RecyclerAdapter(getActivity(), upperArray);
|
229
|
-
RecyclerView mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.upper_recycler_view);
|
230
|
-
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
231
|
-
mRecyclerView.setAdapter(upperAdapter);
|
232
|
-
|
233
|
-
|
234
|
-
ArrayList<String> lowerArray = new ArrayList<>();
|
235
|
-
for (Integer i=0; i<10; i++) {
|
236
|
-
lowerArray.add("lower " + i.toString());
|
237
|
-
}
|
238
|
-
RecyclerAdapter lowerAdapter = new RecyclerAdapter(getActivity(), lowerArray);
|
239
|
-
RecyclerView mRecyclerView2 = (RecyclerView) mRootView.findViewById(R.id.lower_recycler_view);
|
240
|
-
mRecyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
|
241
|
-
mRecyclerView2.setAdapter(lowerAdapter);
|
242
|
-
}
|
243
|
-
}
|
244
|
-
```
|
245
|
-
|
246
|
-
fragment_blank.xml
|
247
|
-
```xml
|
248
|
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
249
|
-
android:orientation="vertical"
|
250
|
-
android:layout_width="match_parent"
|
251
|
-
android:layout_height="match_parent" >
|
252
|
-
|
253
|
-
<android.support.v4.widget.NestedScrollView
|
254
|
-
android:layout_width="match_parent"
|
255
|
-
android:layout_height="match_parent">
|
256
|
-
|
257
|
-
<LinearLayout
|
258
|
-
android:orientation="vertical"
|
259
|
-
android:layout_width="match_parent"
|
260
|
-
android:layout_height="match_parent">
|
261
|
-
|
262
|
-
<android.support.v7.widget.RecyclerView
|
263
|
-
android:id="@+id/upper_recycler_view"
|
264
|
-
android:layout_width="match_parent"
|
265
|
-
android:layout_height="wrap_content" />
|
266
|
-
|
267
|
-
<View
|
268
|
-
android:background="#ff00ff00"
|
269
|
-
android:layout_width="match_parent"
|
270
|
-
android:layout_height="200dp" />
|
271
|
-
|
272
|
-
<android.support.v7.widget.RecyclerView
|
273
|
-
android:id="@+id/lower_recycler_view"
|
274
|
-
android:layout_width="match_parent"
|
275
|
-
android:layout_height="wrap_content" />
|
276
|
-
|
277
|
-
</LinearLayout>
|
278
|
-
|
279
|
-
</android.support.v4.widget.NestedScrollView>
|
280
|
-
|
281
|
-
</LinearLayout>
|
282
|
-
```
|
283
|
-
|
284
|
-
build.gradleのdependencies
|
285
|
-
```gradle
|
286
|
-
dependencies {
|
287
|
-
compile fileTree(dir: 'libs', include: ['*.jar'])
|
288
|
-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
289
|
-
exclude group: 'com.android.support', module: 'support-annotations'
|
290
|
-
})
|
291
|
-
compile 'com.android.support:appcompat-v7:24.2.1'
|
292
|
-
compile 'com.android.support:design:24.2.1'
|
293
|
-
compile 'com.android.support:support-v4:24.2.1'
|
294
|
-
compile 'com.android.support:recyclerview-v7:24.2.1'
|
295
|
-
testCompile 'junit:junit:4.12'
|
296
|
-
}
|
297
|
-
```
|
298
|
-
|
299
19
|
###試したこと
|
300
20
|
真ん中のViewが表示されない位置で試すと再現しない
|
301
21
|
エミュレータでも試してみましたが同様の結果でした。
|
4
最後の画像がToolbarが表示されているものだったので、バグ発生直後の表示されていないものに更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|

|
30
30
|
|
31
31
|
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
32
|
-

|
33
33
|
|
34
34
|
###該当のソースコード
|
35
35
|
activity_main.xml
|
3
BlankFragmentでfindViewIdしている箇所をgetActivity\(\)からmRootViewに変更、画像も更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,10 +23,10 @@
|
|
23
23
|

|
24
24
|
|
25
25
|
スワイプで画面切り替え
|
26
|
-

|
27
27
|
|
28
28
|
元のページに戻り中
|
29
|
-

|
30
30
|
|
31
31
|
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
32
32
|

|
@@ -177,6 +177,8 @@
|
|
177
177
|
private String mParam1;
|
178
178
|
private String mParam2;
|
179
179
|
|
180
|
+
private View mRootView;
|
181
|
+
|
180
182
|
public BlankFragment() {
|
181
183
|
}
|
182
184
|
|
@@ -201,7 +203,8 @@
|
|
201
203
|
@Override
|
202
204
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
203
205
|
Bundle savedInstanceState) {
|
204
|
-
|
206
|
+
mRootView = inflater.inflate(R.layout.fragment_blank, container, false);
|
207
|
+
return mRootView;
|
205
208
|
}
|
206
209
|
|
207
210
|
@Override
|
@@ -223,7 +226,7 @@
|
|
223
226
|
upperArray.add("upper " + i.toString());
|
224
227
|
}
|
225
228
|
RecyclerAdapter upperAdapter = new RecyclerAdapter(getActivity(), upperArray);
|
226
|
-
RecyclerView mRecyclerView = (RecyclerView)
|
229
|
+
RecyclerView mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.upper_recycler_view);
|
227
230
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
228
231
|
mRecyclerView.setAdapter(upperAdapter);
|
229
232
|
|
@@ -233,7 +236,7 @@
|
|
233
236
|
lowerArray.add("lower " + i.toString());
|
234
237
|
}
|
235
238
|
RecyclerAdapter lowerAdapter = new RecyclerAdapter(getActivity(), lowerArray);
|
236
|
-
RecyclerView mRecyclerView2 = (RecyclerView)
|
239
|
+
RecyclerView mRecyclerView2 = (RecyclerView) mRootView.findViewById(R.id.lower_recycler_view);
|
237
240
|
mRecyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
|
238
241
|
mRecyclerView2.setAdapter(lowerAdapter);
|
239
242
|
}
|
2
説明画像を追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,7 +25,10 @@
|
|
25
25
|
スワイプで画面切り替え
|
26
26
|

|
27
27
|
|
28
|
-
元のページに戻
|
28
|
+
元のページに戻り中
|
29
|
+

|
30
|
+
|
31
|
+
元のページに戻りきった直後にScrollToされたかのように位置が変わる
|
29
32
|

|
30
33
|
|
31
34
|
###該当のソースコード
|
1
エミュレータでも試した旨追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -292,6 +292,7 @@
|
|
292
292
|
|
293
293
|
###試したこと
|
294
294
|
真ん中のViewが表示されない位置で試すと再現しない
|
295
|
+
エミュレータでも試してみましたが同様の結果でした。
|
295
296
|
|
296
297
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
297
298
|
端末: xperia z1
|