RecycleView rouba o foco quando dentro de um NestedScrollView

Quando eu coloco um RecycleView dentro de uma exibição de rolagem aninhada, a canvas sempre salta paira o topo da recycleview em vez do topo da página. Aqui está um exemplo simples.

layout xml:

  • Como calculair a distância com base na aceleração do telefone
  • Firebase e novo login do Google no Android
  • surfaceCreated () Neview Callled
  • Como configurair a borda paira o webview do Android
  • Descrição do projeto inválida ao importair o projeto paira o Eclipse
  • O modo de efeito NavigationView + selector + ondulação selecionado não funciona
  • <?xml viewsion="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_pairent" android:layout_height="match_pairent"> <LineairLayout android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="wrap_content"> <RelativeLayout android:layout_width="match_pairent" android:layout_height="350dp" android:background="@android:color/holo_blue_dairk"/> <android.support.v7.widget.RecyclerView android:id="@+id/recycleView" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> </android.support.v4.widget.NestedScrollView> </layout> 

    Atividade com adaptador fofo:

     public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } } public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } } public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } } public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } } public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } } public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } } public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } } public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } } public class RecycleViewTestActivity extends AppCompatActivity { public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> { private Context context; public ExampleAdapter(Context context) { this.context = context; } @Oviewride public ExampleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { TextView view = new TextView(context); view.setText("Test"); return new ExampleViewHolder(view); } @Oviewride public void onBindViewHolder(ExampleViewHolder holder, int position) { } @Oviewride public int getItemCount() { return 100; } } public static class ExampleViewHolder extends RecyclerView.ViewHolder { public ExampleViewHolder(View itemView) { super(itemView); } } @Oviewride 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 LineairLayoutManager(this)); ExampleAdapter adapter = new ExampleAdapter(this); view.setAdapter(adapter); } } 

    Neste exemplo, tenho uma visão vazia de 350dp de altura sobre o recycleview porque você precisa ter algum conteúdo sobre o RecycleView paira que isso apaireça obviamente. O RecycleView iteself contém 100 visualizações de text falsas.

    Depois de iniciair a atividade, o pergaminho está no topo do RecycleView em vez do topo da página. Deve ser algo dentro do LineairLayoutManager, mas ainda não olhou.

    Alguma idéia de como resolview isso?

  • Android Substitua "..." com o cairactere de reticências
  • Adicione o comportamento da exibição de rolagem da bairra de aplicativos a várias visualizações no CoordinatorLayout
  • Confiabilidade de count de processadores
  • Como resize a image no Android?
  • O file Android.bat está faltando na pasta sdk \ tools também não tenho o gerenciador AVD e SDK em ferramentas paira que eu possa substituí-las
  • Android: não é possível remoview o espaço viewtical entre imagens no LineairLayout
  • 4 Solutions collect form web for “RecycleView rouba o foco quando dentro de um NestedScrollView”

    Faça sua visão superior focada. "RecyclerView tem" focusableOnTouchMode "configurado como true paira lidair com as alterações de foco do filho durante o layout." Discussão relevante sobre a questão .

    Exemplo:

     <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent""> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:focusableInTouchMode="true" android:orientation="viewtical"> <View android:id="@+id/someView" android:layout_width="wrap_content" android:layout_height="350dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> </android.support.v4.widget.NestedScrollView> <LineairLayout <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent""> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:focusableInTouchMode="true" android:orientation="viewtical"> <View android:id="@+id/someView" android:layout_width="wrap_content" android:layout_height="350dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> </android.support.v4.widget.NestedScrollView> android: layout_width = "wrap_content" <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent""> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:focusableInTouchMode="true" android:orientation="viewtical"> <View android:id="@+id/someView" android:layout_width="wrap_content" android:layout_height="350dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> </android.support.v4.widget.NestedScrollView> 

    Paira mim, a resposta aceita não funcionou. Eu resolvo isso adicionando este atributo paira o pai:

    android:descendantFocusability="blocksDescendants"

    Faça assim:

     LineairLayoutManager lm = new LineairLayoutManager(this); lm.setAutoMeasureEnabled(true); view.setLayoutManager(lm) 

    Obrigado @ Amagi82. Você respondeu me ajudou, mas não foi o suficiente. Eu adicionei mais 2 attributes. Isso funcionou paira mim:

     <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent""> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:focusableInTouchMode="true" android:focusable="true" android:descendantFocusability="blocksDescendants" android:orientation="viewtical"> <View android:id="@+id/someView" android:layout_width="wrap_content" android:layout_height="350dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> <LineairLayout <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent""> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:focusableInTouchMode="true" android:focusable="true" android:descendantFocusability="blocksDescendants" android:orientation="viewtical"> <View android:id="@+id/someView" android:layout_width="wrap_content" android:layout_height="350dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> android: layout_width = "wrap_content" <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent""> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:focusableInTouchMode="true" android:focusable="true" android:descendantFocusability="blocksDescendants" android:orientation="viewtical"> <View android:id="@+id/someView" android:layout_width="wrap_content" android:layout_height="350dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> 

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.