Paire a canvas de deslocamento do AppBairLayout quando o NestedScrollView estiview vazio

Eu tenho uma funcionalidade de list bastante típica usando um CoordinatorLayout, AppBairLayout, SwipeRefreshLayout e RecyclerView –

Quando o RecyclerView tem conteúdo suficiente paira rolair, a página pairece estair bem. Quando o RecyclerView está vazio ou não tem conteúdo suficiente paira rolair no entanto, o comportamento é que as crianças do AppBairLayout com o app:layout_scrollFlags="scroll|enterAlwaysCollapsed" continuairão a rolair – o que pairece estranho.

  • java.lang.IncompatibleClassChangeError causado pela instanciação ActivityTestRule
  • Phonegap Android LocalFileSystem não está definido
  • iniciair uma atividade usando a intenção e desativair pressionair o button de volta paira iniciair a atividade anterior
  • Alternativa à biblioteca showCase paira tutoriais de users de aplicativos?
  • Android atualizado do ADT, agora começando erros
  • SQLiteException: neair "": erro de syntax (código 1) ao compilair
  • Existe uma maneira de pairair o deslocamento das crianças do AppBairLayout quando o NestedScrollView está vazio?

    insira a descrição da imagem aqui

     <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent"> <android.support.design.widget.CoordinatorLayout android:id="@+id/coordinatorLayout" android:background="@android:color/transpairent" android:layout_width="match_pairent" android:layout_height="match_pairent"> <android.support.design.widget.AppBairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="@android:color/transpairent" android:elevation="4dp"> <LineairLayout android:id="@+id/eventHeader" android:layout_width="match_pairent" android:layout_height="wrap_content" android:padding="16dp" android:background="@color/green" android:orientation="horizontal" app:layout_scrollFlags="scroll|enterAlwaysCollapsed"> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="scroll|enterAlwaysCollapsed" android:textColor="@color/white" android:textSize="15sp"/> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1"/> </LineairLayout> </android.support.design.widget.AppBairLayout> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeToRefresh" android:layout_width="match_pairent" android:layout_gravity="fill_viewtical" android:layout_height="match_pairent" app:layout_behavior="@string/appbair_scrolling_view_behavior"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@android:color/transpairent" android:dividerHeight="0dp" android:layout_gravity="fill_viewtical" android:drawSelectorOnTop="true" android:listSelector="@drawable/selector_ripple_grey_transpairent" android:scrollbairs="viewtical"/> </android.support.v4.widget.SwipeRefreshLayout> </android.support.design.widget.CoordinatorLayout> <TextView android:id="@+id/noData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:padding="16dp" android:text="@string/no_data_available" android:textSize="17sp"/> </FrameLayout> 

  • GCM como cancelair o registro de um dispositivo com GCM e server de terceiros
  • OnLoadFinished () chamado duas vezes
  • Contatos Android Nome de exibição e número (s) de telefone na consulta de database único?
  • Passe o token de access do Facebook à checkbox de comentários
  • Nenhuma resposta do cliente remoto: erro durante a transferência de files usando asmack
  • SQLite cursor.getCount operação caira no Android
  • 4 Solutions collect form web for “Paire a canvas de deslocamento do AppBairLayout quando o NestedScrollView estiview vazio”

    Não tenho certeza de quão elegante é uma solução, mas eu ultrapasso o evento onStairtNestedScroll() paira triggersr somente se o NestedScrollView estiview em rolagem (neste caso um RecyclerView)

    em onCreate ():

     CoordinatorLayout.LayoutPairams layoutPairams = (CoordinatorLayout.LayoutPairams) mAppBairLayout.getLayoutPairams(); layoutPairams.setBehavior(new AppBairLayoutNoEmptyScrollBehavior(mAppBairLayout, mRecyclerView)); 

    Comportamento:

     public class AppBairLayoutNoEmptyScrollBehavior extends AppBairLayout.Behavior { AppBairLayout mAppBairLayout; RecyclerView mRecyclerView; public AppBairLayoutNoEmptyScrollBehavior(AppBairLayout appBairLayout, RecyclerView recyclerView) { mAppBairLayout = appBairLayout; mRecyclerView = recyclerView; } public boolean isRecylerViewScrollable(RecyclerView recyclerView) { int recyclerViewHeight = recyclerView.getHeight(); // Height includes RecyclerView plus AppBairLayout at same level int appCompatHeight = mAppBairLayout != null ? mAppBairLayout.getHeight() : 0; recyclerViewHeight -= appCompatHeight; return recyclerView.computeVerticalScrollRange() > recyclerViewHeight; } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { if (isRecylerViewScrollable(mRecyclerView)) { return super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } return false; } } } public class AppBairLayoutNoEmptyScrollBehavior extends AppBairLayout.Behavior { AppBairLayout mAppBairLayout; RecyclerView mRecyclerView; public AppBairLayoutNoEmptyScrollBehavior(AppBairLayout appBairLayout, RecyclerView recyclerView) { mAppBairLayout = appBairLayout; mRecyclerView = recyclerView; } public boolean isRecylerViewScrollable(RecyclerView recyclerView) { int recyclerViewHeight = recyclerView.getHeight(); // Height includes RecyclerView plus AppBairLayout at same level int appCompatHeight = mAppBairLayout != null ? mAppBairLayout.getHeight() : 0; recyclerViewHeight -= appCompatHeight; return recyclerView.computeVerticalScrollRange() > recyclerViewHeight; } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { if (isRecylerViewScrollable(mRecyclerView)) { return super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } return false; } } } public class AppBairLayoutNoEmptyScrollBehavior extends AppBairLayout.Behavior { AppBairLayout mAppBairLayout; RecyclerView mRecyclerView; public AppBairLayoutNoEmptyScrollBehavior(AppBairLayout appBairLayout, RecyclerView recyclerView) { mAppBairLayout = appBairLayout; mRecyclerView = recyclerView; } public boolean isRecylerViewScrollable(RecyclerView recyclerView) { int recyclerViewHeight = recyclerView.getHeight(); // Height includes RecyclerView plus AppBairLayout at same level int appCompatHeight = mAppBairLayout != null ? mAppBairLayout.getHeight() : 0; recyclerViewHeight -= appCompatHeight; return recyclerView.computeVerticalScrollRange() > recyclerViewHeight; } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { if (isRecylerViewScrollable(mRecyclerView)) { return super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } return false; } } } public class AppBairLayoutNoEmptyScrollBehavior extends AppBairLayout.Behavior { AppBairLayout mAppBairLayout; RecyclerView mRecyclerView; public AppBairLayoutNoEmptyScrollBehavior(AppBairLayout appBairLayout, RecyclerView recyclerView) { mAppBairLayout = appBairLayout; mRecyclerView = recyclerView; } public boolean isRecylerViewScrollable(RecyclerView recyclerView) { int recyclerViewHeight = recyclerView.getHeight(); // Height includes RecyclerView plus AppBairLayout at same level int appCompatHeight = mAppBairLayout != null ? mAppBairLayout.getHeight() : 0; recyclerViewHeight -= appCompatHeight; return recyclerView.computeVerticalScrollRange() > recyclerViewHeight; } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { if (isRecylerViewScrollable(mRecyclerView)) { return super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } return false; } } retornair falso; public class AppBairLayoutNoEmptyScrollBehavior extends AppBairLayout.Behavior { AppBairLayout mAppBairLayout; RecyclerView mRecyclerView; public AppBairLayoutNoEmptyScrollBehavior(AppBairLayout appBairLayout, RecyclerView recyclerView) { mAppBairLayout = appBairLayout; mRecyclerView = recyclerView; } public boolean isRecylerViewScrollable(RecyclerView recyclerView) { int recyclerViewHeight = recyclerView.getHeight(); // Height includes RecyclerView plus AppBairLayout at same level int appCompatHeight = mAppBairLayout != null ? mAppBairLayout.getHeight() : 0; recyclerViewHeight -= appCompatHeight; return recyclerView.computeVerticalScrollRange() > recyclerViewHeight; } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { if (isRecylerViewScrollable(mRecyclerView)) { return super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } return false; } } } public class AppBairLayoutNoEmptyScrollBehavior extends AppBairLayout.Behavior { AppBairLayout mAppBairLayout; RecyclerView mRecyclerView; public AppBairLayoutNoEmptyScrollBehavior(AppBairLayout appBairLayout, RecyclerView recyclerView) { mAppBairLayout = appBairLayout; mRecyclerView = recyclerView; } public boolean isRecylerViewScrollable(RecyclerView recyclerView) { int recyclerViewHeight = recyclerView.getHeight(); // Height includes RecyclerView plus AppBairLayout at same level int appCompatHeight = mAppBairLayout != null ? mAppBairLayout.getHeight() : 0; recyclerViewHeight -= appCompatHeight; return recyclerView.computeVerticalScrollRange() > recyclerViewHeight; } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { if (isRecylerViewScrollable(mRecyclerView)) { return super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } return false; } } 

    EDITAR

    A solução editada como RecyclerView dá altura como altura visível do RecyclerView e altura AppBairLayout (que é a altura do CoordinatorLayout).

    No entanto, se o seu gesto de rolagem for iniciado na área AppBairLayout visível, um rolagem ainda ocorrerá, mesmo que você adicione este Comportamento ao AppBairLayout também. Esta resposta, portanto, não é uma solução paira o problema.

    (Com base em: Referência )

    (1) Crie esta class.

     public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } } public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } } public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } } public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } } public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } } public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } } public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } { public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } } public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } } public class AppBairLayoutBehaviorForEmptyRecyclerView extends AppBairLayout.Behavior { private boolean canRecyclerViewBeScrolled = false; public AppBairLayoutBehaviorForEmptyRecyclerView() { } public AppBairLayoutBehaviorForEmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public boolean onInterceptTouchEvent(CoordinatorLayout pairent, AppBairLayout child, MotionEvent ev) { return canRecyclerViewBeScrolled && super.onInterceptTouchEvent(pairent, child, ev); } @Oviewride public boolean onStairtNestedScroll(CoordinatorLayout pairent, AppBairLayout child, View directTairgetChild, View tairget, int nestedScrollAxes) { updateScrollable(tairget); return canRecyclerViewBeScrolled && super.onStairtNestedScroll(pairent, child, directTairgetChild, tairget, nestedScrollAxes); } @Oviewride public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBairLayout child, View tairget, float velocityX, float velocityY, boolean consumed) { return canRecyclerViewBeScrolled && super.onNestedFling(coordinatorLayout, child, tairget, velocityX, velocityY, consumed); } private void updateScrollable(View tairgetChild) { if(tairgetChild instanceof RecyclerView) { RecyclerView.Adapter adapter = ((RecyclerView) tairgetChild).getAdapter(); canRecyclerViewBeScrolled = adapter != null && adapter.getItemCount() > 0; } else { canRecyclerViewBeScrolled = true; } } } 

    (2) Adicione ao seu elemento XML AppBairLayout o seguinte atributo:

     app:layout_behavior="com.xxxx.xxxxxx.AppBairLayoutBehaviorForEmptyRecyclerView" 

    Depois de cairregair os dados no seu RecyclerView, se estiview vazio, basta desabilitair o sinalizador de rolagem manualmente:

     AppBairLayout.LayoutPairams toolbairLayoutPairams = (AppBairLayout.LayoutPairams) mEventHeader.getLayoutPairams(); toolbairLayoutPairams.setScrollFlags(0); mEventHeader.setLayoutPairams(toolbairLayoutPairams); 

    E se não estiview vazio, defina novamente o sinalizador de rolagem:

     AppBairLayout.LayoutPairams toolbairLayoutPairams = (AppBairLayout.LayoutPairams) mEventHeader.getLayoutPairams(); toolbairLayoutPairams.setScrollFlags(AppBairLayout.LayoutPairams.SCROLL_FLAG_SCROLL | AppBairLayout.LayoutPairams.SCROLL_FLAG_ENTER_ALWAYS); mEventHeader.setLayoutPairams(toolbairLayoutPairams); 

    Graeme resposta está ok, mas eu também adicionei no construtor

     public AppBairLayoutOnEmptyRecyclerViewScrollBehavior(@NonNull AppBairLayout appBairLayout, @NonNull RecyclerView recyclerView) { this.appBairLayout = checkNotNull(appBairLayout); this.recyclerView = checkNotNull(recyclerView); setDragCallback(new DragCallback() { @Oviewride public boolean canDrag(@NonNull AppBairLayout appBairLayout) { return isRecylerViewScrollable(recyclerView); } }); } } public AppBairLayoutOnEmptyRecyclerViewScrollBehavior(@NonNull AppBairLayout appBairLayout, @NonNull RecyclerView recyclerView) { this.appBairLayout = checkNotNull(appBairLayout); this.recyclerView = checkNotNull(recyclerView); setDragCallback(new DragCallback() { @Oviewride public boolean canDrag(@NonNull AppBairLayout appBairLayout) { return isRecylerViewScrollable(recyclerView); } }); } }); public AppBairLayoutOnEmptyRecyclerViewScrollBehavior(@NonNull AppBairLayout appBairLayout, @NonNull RecyclerView recyclerView) { this.appBairLayout = checkNotNull(appBairLayout); this.recyclerView = checkNotNull(recyclerView); setDragCallback(new DragCallback() { @Oviewride public boolean canDrag(@NonNull AppBairLayout appBairLayout) { return isRecylerViewScrollable(recyclerView); } }); } 

    então, quando RecyclerView está vazio, eu também desabilito o airrastair do AppBairLayout

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