我遇到了一个很奇怪的问题,以前从未经历过。
我有一个视图(BottomSheet),它封装了一个RecyclerView和它的空视图。我将它们之一设为View.GONE,另一种设为View.VISIBLE,具体取决于是否有要显示的项目。由于需要让用户能够将BottomSheet向上或向下移动,因此空视图实际上被包裹在NestedScrollView中。
问题是,根据我的视图结构如何组织,滚动实际上是在RecyclerView或NestedScrollView上进行的,无论我先放哪个,而不是两者兼具。它们的父对象是RelativeLayout(请查看下面的代码)。
我有一个视图(BottomSheet),它封装了一个RecyclerView和它的空视图。我将它们之一设为View.GONE,另一种设为View.VISIBLE,具体取决于是否有要显示的项目。由于需要让用户能够将BottomSheet向上或向下移动,因此空视图实际上被包裹在NestedScrollView中。
问题是,根据我的视图结构如何组织,滚动实际上是在RecyclerView或NestedScrollView上进行的,无论我先放哪个,而不是两者兼具。它们的父对象是RelativeLayout(请查看下面的代码)。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/BottomSheet"
>
<androidx.core.widget.NestedScrollView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_marginTop="115dp"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="7dp"
android:textAlignment="center"
/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<com.myproject.CustomRecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="36dp"
android:paddingTop="10dp"
app:emptyView="@id/empty_view"
/>
</RelativeLayout>
android:layout_below="@id/header"
头部在哪里?android:visibility="gone" tools:visibility="visible"
为什么你有两个这样的? - Zunandroid:visibility="gone"
在启动时隐藏视图,但使用tools:visibility="visible"
是因为它让我看到空视图是否在设计上OK。 - brf42