【发布时间】:2019-07-01 13:26:00
【问题描述】:
我正在将我的应用程序从 appcompat 迁移到 AndroidX。除了我无法为androidx.core.widget.NestedScrollView 和
androidx.recyclerview.widget.RecyclerView.
我已经尝试添加
setHasFixedSize(true)
setNestedScrollingEnabled(false)
但它不起作用。我的 XML 现在看起来是这样的:
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
android:clipToPadding="false"
android:id="@+id/scroll"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingBottom="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:background="@color/white"
android:id="@+id/itenarydays"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<FrameLayout
android:background="@drawable/roundshape"
android:layout_gravity="center"
android:layout_height="56dp"
android:layout_margin="3dp"
android:layout_width="56dp"
android:padding="@dimen/textsise10">
<ImageView
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:tint="@color/white"
app:srcCompat="@drawable/ic_sketch" />
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:animationCache="true"
android:clipToPadding="false"
android:id="@+id/list_daycount"
android:layout_gravity="center"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"></androidx.recyclerview.widget.RecyclerView>
<FrameLayout
android:background="@drawable/shape_redround"
android:id="@+id/framelyt_add"
android:layout_gravity="center"
android:layout_height="56dp"
android:layout_margin="3dp"
android:layout_width="56dp"
android:padding="@dimen/textsise10">
<ImageView
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:tint="@color/white"
app:srcCompat="@drawable/ic_plus" />
</FrameLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
【问题讨论】:
-
不要将 RecyclerView 放在另一个滚动视图中。
-
在 app-compat 中工作,而不是在 androidx 中
-
@EugenPechanec 如果在 RV 上禁用了嵌套滚动,您绝对可以在其他滚动视图中拥有 recyclerviews。
-
@BrandonMcAnsh 我相当关心 RecyclerView 的回收方面。 ScrollView 不会回收其内容。如果您将垂直 wrap_content RV 放在垂直 SV 中,则不会进行回收。整个视图层次结构将始终在内存中。一个更好的想法是将整个视图层次结构调整为单个垂直 RV 的不同项目类型。
标签: android android-recyclerview androidx nestedscrollview