【发布时间】:2019-08-02 13:32:25
【问题描述】:
我遇到了一个以前从未遇到过的非常奇怪的问题。
所以,我有一个视图 (BottomSheet),它封装了 RecyclerView 及其空视图。我将其中一个设置为View.GONE,另一个设置为View.VISIBLE,具体取决于是否有要显示的项目。
空视图实际上包含在 NestedScrollView 中,因为我需要能够滚动它以便用户能够向上或向下移动 BottomSheet。
问题是,取决于我如何构建视图,滚动实际上是在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"你为什么有这两个 -
我相应地编辑了问题,视图实际上有点复杂,但这是问题的核心(如果我准确地说,我会遇到同样的问题)。我有
android:visibility="gone"来隐藏启动时的视图,但tools:visibility="visible"因为它让我看到空视图在设计方面是否可以
标签: android android-recyclerview