android - RecyclerView 不滚动
问题描述
我有一个 RecyclerView 的问题:它不滚动,这是我的布局:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardElevation="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/square3"
android:src="@drawable/square"/>
<LinearLayout
android:layout_width="60dp"
android:layout_height="wrap_content"
android:id="@+id/lin"
android:orientation="vertical">
<TextView
android:id="@+id/day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nameeOfMonthTable"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recicloEvent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginRight="26dp"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/lin"
android:layout_alignBottom="@+id/square3"
android:layout_alignTop="@+id/square3"
android:layout_marginBottom="25dp"
android:paddingLeft="1dp"/>
<View
android:id="@+id/separatorDateRvCale2"
android:layout_width="1dp"
android:layout_alignTop="@+id/square3"
android:layout_height="200dp"
android:layout_alignBottom="@+id/square3"
android:layout_alignLeft="@+id/recicloEvent"
/>
<View
android:id="@+id/separatorDateRvCale"
android:layout_width="1dp"
android:layout_alignTop="@+id/square3"
android:layout_height="200dp"
android:layout_alignBottom="@+id/square3"
android:layout_alignLeft="@+id/recicloEvent"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
这是另一个正确滚动的 RecyclerView 的适配器:上部 RecyclerView 在另一个 RecyclerView 内部(不正确滚动的那个) 问题只影响内表(即向上的那个)。我该如何解决这个问题?这是一个屏幕:,问题影响在底部切割的 RecyclerView
解决方案
尝试将整个布局放在 NestedScrollView 中,如下所示
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/square3"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/square" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:id="@+id/separatorDateRvCale2"
android:layout_width="1dp"
android:layout_height="200dp" />
<View
android:id="@+id/separatorDateRvCale"
android:layout_width="1dp"
android:layout_height="200dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recicloEvent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginRight="26dp"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/lin"
android:layout_weight="1"
android:paddingLeft="1dp" />
<LinearLayout
android:id="@+id/lin"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/day"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/nameeOfMonthTable"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
推荐阅读
- python - 使用 numpy 操作实现 conv1d
- mongoose - 如何编写在参考中搜索 id 的查找查询?
- c# - ASP.NET Core 未同时响应所有请求 Http
- python - 如何在 Python 中使用 Selenium 上传选定的文件?
- android-studio - 如何在 Linux 上将 SUBSYSTEM==”usb”, ATTR{idVendor}==”04E8″, MODE=”0666″, GROUP=”plugdev” 添加到我的 51-android.rules?
- javascript - 合并复选框所需的 jQuery 代码以缩短代码
- ios - Swift 5 Alamofire 字典解析错误
- python - 如何将 pandas 分配功能与个人定义的功能一起使用?
- php - 在下拉列表中获取选定值 - MySQL、PHP、HTML
- bash - 为什么当我使用 `>` 操作符对已重定向的文件进行 `tail -f` 时出现不一致的行为