Когда я помещаю RecycleView внутри вложенного scrollview, экран всегда перескакивает вверху recycleview, а не вверху страницы. Вот простой пример.
layout xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="@android:color/holo_blue_dark"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
Активность с фиктивным адаптером:
public class RecycleViewTestActivity extends AppCompatActivity {
public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> {
private Context context;
public ExampleAdapter(Context context) {
this.context = context;
}
@Override
public ExampleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
TextView view = new TextView(context);
view.setText("Test");
return new ExampleViewHolder(view);
}
@Override
public void onBindViewHolder(ExampleViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 100;
}
}
public static class ExampleViewHolder extends RecyclerView.ViewHolder {
public ExampleViewHolder(View itemView) {
super(itemView);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rectest);
RecyclerView view = (RecyclerView) findViewById(R.id.recycleView);
view.setNestedScrollingEnabled(false);
view.setLayoutManager(new LinearLayoutManager(this));
ExampleAdapter adapter = new ExampleAdapter(this);
view.setAdapter(adapter);
}
}
В этом примере у меня есть 350dp высокий пустой вид на recycleview, потому что вам нужно иметь некоторый контент над RecycleView, чтобы это явно отображалось. RecycleView itestelf содержит 100 фиктивных текстовых просмотров.
После запуска операции прокрутка находится вверху RecycleView, а не вверху страницы. Это должно быть что-то внутри LinearLayoutManager, но havent действительно выглядел еще.
Есть идеи, как это решить?