Java RecyclerView没有';当它';它位于嵌套的滚动视图中
我的Java RecyclerView没有';当它';它位于嵌套的滚动视图中,java,android,android-layout,android-recyclerview,Java,Android,Android Layout,Android Recyclerview,我的RecyclerView在滚动时不显示动画。我已经将问题缩小到RecyclerView所在的NestedScrollView。当RecyclerView位于NestedScrollView之外时,其动画效果良好。但是当它在NestedScrollView中时,它不会。如何在保持嵌套滚动视图的同时设置回收视图的动画 以下是相关布局: <androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_wi
RecyclerView
在滚动时不显示动画。我已经将问题缩小到RecyclerView
所在的NestedScrollView
。当RecyclerView
位于NestedScrollView
之外时,其动画效果良好。但是当它在NestedScrollView
中时,它不会。如何在保持嵌套滚动视图
的同时设置回收视图
的动画
以下是相关布局:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mainToolbar">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/tab_anim_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="@android:color/transparent"
app:elevation="0dp">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/searchToolbar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:background="#A106A1"
android:elevation="2dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways">
<!-- dummy to catch focus -->
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:animateLayoutChanges="true"
android:layoutDirection="rtl"
app:iconifiedByDefault="true"
app:searchHintIcon="@null" />
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="1dp" />
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
更新:这里使用的是折叠工具栏布局
,而不是嵌套滚动视图
。如何使工具栏滚动
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mainToolbar">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/tab_anim_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="@android:color/transparent"
app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/searchToolbar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:background="#A106A1"
android:elevation="2dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll">
<!-- dummy to catch focus -->
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:animateLayoutChanges="true"
android:layoutDirection="rtl"
app:iconifiedByDefault="true"
app:searchHintIcon="@null" />
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
将RecyclerView放在NestedScrollView中不是一个好方法。如果您想在RecyclerView上方创建搜索栏,可以进行检查
您还可以检查引用。将RecyclerView放入NestedScrollView中不是一个好方法。如果您想在RecyclerView上方创建搜索栏,可以进行检查
您也可以检查引用。我检查了您的xml并对其进行了修改。它在我这边起作用。请根据您的用户界面要求进行修改 注意:在recyclerview上填充数据后进行检查。首先,由于recyclerview上没有数据,它似乎不起作用
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
tools:context=".MainActivity"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/tab_anim_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:fitsSystemWindows="true"
android:background="@android:color/transparent"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar_scrolling">
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:animateLayoutChanges="true"
android:background="@drawable/rounded_bg"
android:layoutDirection="rtl"
app:iconifiedByDefault="true"
app:searchHintIcon="@null" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
四舍五入的\u bg\u action\u bar.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/holo_purple" />
<corners android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp" />
</shape>
rounded_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/holo_purple" />
<corners android:bottomLeftRadius="100dp"
android:bottomRightRadius="100dp" />
</shape>
我检查了您的xml并对其进行了修改。它在我这边起作用。请根据您的用户界面要求进行修改 注意:在recyclerview上填充数据后进行检查。首先,由于recyclerview上没有数据,它似乎不起作用
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
tools:context=".MainActivity"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/tab_anim_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:fitsSystemWindows="true"
android:background="@android:color/transparent"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar_scrolling">
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:animateLayoutChanges="true"
android:background="@drawable/rounded_bg"
android:layoutDirection="rtl"
app:iconifiedByDefault="true"
app:searchHintIcon="@null" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
四舍五入的\u bg\u action\u bar.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/holo_purple" />
<corners android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp" />
</shape>
rounded_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/holo_purple" />
<corners android:bottomLeftRadius="100dp"
android:bottomRightRadius="100dp" />
</shape>
没有人?求你了(我不知道你为什么首先将RecyclerView放在NestedScrollView中。这种方式将禁用回收,因为NSV到caclulate大小将迫使RV膨胀所有的视图持有者(与列表大小一样多)。我还可以如何制作搜索栏(它是RecyclerView上方的工具栏)除了recyclerView?@Rinat,有没有一种方法可以不用NestedScrollView来实现这一点?没有人?请?:(我不知道你为什么要首先将recyclerView放在NestedScrollView中。这种方法将禁用回收,因为NSV到caclulate大小将迫使RV膨胀所有的视图持有者(与列表大小一样多)。我还可以如何制作搜索栏(它是recyclerView上方的工具栏)在RecycleView旁边?@Rinat有没有办法不使用NestedScrollView就可以做到这一点?我还可以如何使搜索栏在RecycleView旁边上下滚动?您可以查看我共享的第二个引用。或者您可以在ScrollView内使用带有RecycleView或EditText和RecycleView的折叠工具栏。我将尝试折叠工具栏今天。将报告它是否有效。我一整天都在尝试使用折叠工具栏布局,但它不起作用。如果代码与上面相同,折叠工具栏布局
不应该放在AppBarLayout
和MaterialToolbar
之间吗?我应该添加或删除哪些属性?您可以分享您的尝试方式吗?如何操作e我可以让搜索栏在RecycleView旁边上下滚动吗?你可以查看我共享的第二个引用。或者你可以将折叠工具栏与RecycleView或EditText一起使用,并在ScrollView中使用RecycleView。我今天将尝试折叠工具栏。我将报告它是否有效。我已经尝试了一整天使用折叠工具栏布局,它将不起作用。如果代码与上面相同,折叠工具栏布局
不应该放在AppBarLayout
和MaterialToolbar
之间吗?我应该添加或删除哪些属性?你能分享你的尝试吗?那么我应该删除MaterialToolbar
?是的。我认为你可以设计你想要的东西,而不必添加属性帽子。但是我需要MaterialToolBar
来创建圆角。搜索视图应该位于主工具栏以外的第二个工具栏内。你能告诉我你想要如何布局吗?我无法正确地可视化。圆角是使用材质工具栏的唯一原因吗?那么我应该删除material工具栏oolbar
?是的。我想你可以在没有它的情况下设计你想要的东西。但是我需要材料oolbar
来创建圆角。搜索视图应该位于主工具栏以外的第二个工具栏中。你能告诉我你想要如何布局吗?我无法正确地可视化。圆角是你想要的唯一原因吗唱歌材料工具栏?