更新支持库 23.2.1 后,RecyclerView 项目底部有很大的空白空间 [重复]

2024-03-25

我已将支持库更新到 23.2.1,之后 recyclerview 项目会出现很大的空白空间。 虽然我使用的是 recyclerview 并且它的父视图高度为 WRAP_CONTENT。 我的应用程序一次从服务器获取 10 个项目数据,当向上滚动时,它在底部显示一个进度条,因此当时(当进度条显示时)recyclerview 项目显示有非常大的空白空间。

分别用于片段和适配器的 xml 文件的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:paddingTop="?attr/actionBarSize"
        android:scrollbars="vertical"
        android:id="@+id/recycler_view"/>

    <include layout="@layout/date_picker_layout"
        android:id="@+id/date"
        android:layout_height="?attr/actionBarSize"
        android:layout_width="match_parent"/>

    <LinearLayout
        android:layout_width="@dimen/sort_view_width"
        android:layout_height="@dimen/sort_view_height"
        android:visibility="gone"
        android:id="@+id/sort_layout"
        android:background="@drawable/date_picker_selector"
        android:baselineAligned="false"
        android:weightSum="2"
        android:orientation="horizontal"
        android:divider="@drawable/vertical_divider"
        android:layout_gravity="center"
        android:gravity="center"
        android:showDividers="middle"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="@dimen/margin_large"
        android:layout_marginBottom="@dimen/margin_large">

        <ImageView
            android:layout_width="0dp"
            android:layout_height="@dimen/button_size"
            android:layout_weight="1"
            android:padding="@dimen/margin_xxsmall"
            android:id="@+id/low_to_high"
            android:src="@drawable/ic_sort_down"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="@dimen/button_size"
            android:layout_weight="1"
            android:padding="@dimen/margin_xxsmall"
            android:id="@+id/high_to_low"
            android:src="@drawable/ic_sort_up"/>

    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableBottom="@drawable/three_dot"
        android:visibility="gone"
        android:textSize="@dimen/textsize_medium"
        android:text="@string/coming_soon"
        android:id="@+id/no_items"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

适配器.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:wheel="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/itemview">

    <ImageView
        android:id="@+id/image"
        android:layout_height="@dimen/list_image_height"
        android:layout_width="match_parent"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"/>

    <com.example.views.CircularProgressWheel
        android:layout_width="@dimen/progressbar_width"
        android:layout_height="@dimen/progressbar_height"
        android:id="@+id/progress_bar"
        android:visibility="gone"
        wheel:matProg_barColor="@color/primary"
        wheel:matProg_progressIndeterminate="true"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gradient"
        android:layout_alignBottom="@id/image"
        android:id="@+id/relativeLayout2">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/name"
            android:id="@+id/title"
            android:textColor="@color/white"
            android:textSize="@dimen/textsize_medium"
            android:layout_toLeftOf="@+id/price"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="@dimen/margin_xsmall"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin_xsmall"
            android:text="@string/location"
            android:id="@+id/location"
            android:textColor="@color/white"
            android:textSize="@dimen/textsize_medium"
            android:layout_below="@+id/title"
            android:layout_toLeftOf="@+id/price"
            android:layout_alignLeft="@+id/title"
            android:layout_alignStart="@+id/title" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/price"
            android:layout_marginRight="@dimen/margin_xsmall"
            android:id="@+id/price_actual"
            android:textColor="@color/white"
            android:textSize="@dimen/textsize_medium"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/price"
            android:id="@+id/price"
            android:textColor="@color/white"
            android:textSize="@dimen/textsize_medium"
            android:layout_below="@+id/title"
            android:layout_alignRight="@+id/price_actual"
            android:layout_alignEnd="@+id/price_actual" />

    </RelativeLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/margin_xxsmall"
        android:textSize="@dimen/textsize_medium"
        android:background="@drawable/cancel_button_selector"
        android:visibility="gone"
        android:textColor="@color/white"
        android:text="@string/sold_out"
        android:id="@+id/sold_out"
        android:layout_marginRight="@dimen/margin_xsmall"
        android:layout_above="@+id/relativeLayout2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

确保您的回收站视图高度设置为wrap_content. 23.2 http://android-developers.blogspot.ca/2016/02/android-support-library-232.html为 RecyclerView 引入了换行内容功能,如果您希望 RecyclerView 像以前一样工作,您应该将高度设置为wrapp_content。

引用自Android 开发者博客 http://android-developers.blogspot.ca/2016/02/android-support-library-232.html

由于这一变化,请务必仔细检查布局参数 您的项目视图:以前忽略的布局参数(例如 MATCH_PARENT(滚动方向)现在将得到充分尊重。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

更新支持库 23.2.1 后,RecyclerView 项目底部有很大的空白空间 [重复] 的相关文章

  • 启动画面反应本机后出现白屏

    编辑 似乎是因为 MainActivity 加载太重而生成白屏 我设法首先使用本机启动屏幕来解决 然后在本机被杀死后立即基于下一个插件的 js 实现 我做了一些修改完美匹配两个启动画面https github com crazycodebo
  • 如何以编程方式从 mipmap 文件夹加载图像? [复制]

    这个问题在这里已经有答案了 如何从 加载图像mipmap以编程方式保存文件夹 与可绘制对象一样 img setImageResource imageId 我使用的是Android Studio 1 2 1 In 安卓工作室我们有mipmap
  • 如何在发布版本中使用 Zebra EMDK?

    所以我有一台 Zebra MC330M 设备 我之前创建了一个应用程序 我想使用 PDA 内置的条形码扫描仪 如果在调试模式下运行我的应用程序 一切正常 我可以读取条形码 但是如果我创建暂存或释放版本 apk 则条形码读取器不活动 因此如果
  • Android 中的 XmlPullParser 陷入困境

    经过多个小时的搜索和调试后 我仍然停留在同一个地方 并且 Eclipse 没有帮助我 我试图解析这个 RSS 提要 http fr espnf1 com rss motorsport story feeds 0 xml type 2 这很简
  • 如何防止 Activity 在后退操作时重新加载

    我有连接到互联网以获取数据的应用程序 我可以多层次访问数据 假设我从第 3 级开始 在第 4 级我决定返回 每当我按回之前的活动时 就会从互联网重新加载数据 有可能阻止这种情况吗 我尝试以单顶模式运行该活动 将数据加载代码移至 single
  • 使用反向无限滚动添加到 ListView 时保持滚动位置

    我正在构建一个类似聊天的 Android 应用程序 类似于环聊 为此 我使用垂直 ListViewstackFromBottom true and transcriptMode normal 该列表按从较旧的消息 顶部 到较新的消息 底部
  • 如何区分ActionBarSherlock中的两次菜单项点击?

    我最近一直在使用 ActionBarSherlock 并按照各种教程 我编写了这段代码来将项目添加到操作栏 Override public boolean onCreateOptionsMenu Menu menu menu add Ref
  • 如何从另一个应用程序向一个应用程序添加视图

    我的应用程序叫做我的好应用 MyNiceApp 主要只是一个加载视图的核心coreView在主活动中onCreate coreView由用户根据需要下载的其他插件的视图填充 我定义了核心视图上的各个区域 这些区域可以通过 MyNiceApp
  • 在android中以编程方式创建布局 - 问题

    我正在使用以下代码动态创建 FrameLayout mylayout java FrameLayout layout new FrameLayout this FrameLayout LayoutParams layoutparams ne
  • 无法解析配置“:app:debugRuntimeClasspath”的所有文件。问题

    我的 android studio 遇到了下一个问题 导致 org gradle api internal artifacts ivyservice DefaultLenientConfiguration ArtifactResolveEx
  • GSON:自定义对象反序列化

    好吧 我编辑了这个问题 因为它不够清楚 Edit 2 更新了 JSON 文件 我在 Android 应用程序中使用 GSON 我需要解析来自服务器的 JSON 文件 而且有点太复杂了 我不想让我的对象结构太重 所以我想简化内容 所以我的对象
  • 适用于 Droid 手机的数学或 LaTeX 引擎 [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 Android 手机有可用的数学或 LaTeX 引擎吗 我最喜欢的抽认卡应用程序 AnyMemo 似乎
  • 完成特定 Activity 的所有实例

    应用程序中可以有很多活动 最后启动的活动保留在堆栈顶部 按下后它会完成当前活动 我有一系列活动 这是流程 如果我们有 A B C 1 D C 2 活动 C 1 和 C 2 是在导航应用程序时启动的活动 C 的两个不同实例 因此 必需的是清除
  • 在 Android 5 上支持 BLE 外设角色的芯片组 [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 Android 5 0 Lollipop 引入的新 BLE 外设模式将不会在 Nexus 4 5 或 7 上启用 https code
  • 当创建 Android Jetpack Compose AndroidView 的参数发生变化时,如何替换它?

    我有一个应用程序 显示封装在其中的几个不同视图AndroidView 在下面重现的简单示例中 这些只是TextView实例 问题是更改文本 在本例中循环显示三个不同的值 似乎不会更新应用程序显示的内容 sealed class AppVie
  • 如何为工具栏上的溢出菜单中的菜单项设置字体

    我想更改项目的默认字体溢出菜单并设置自定义字体 我尝试添加一个工厂LayoutInflater并在onCreateView 方法我改变了TextView的字体 但这没有用 这是代码 在 onCreateOptionsMenu 内 getLa
  • Webview 中的 Java 空指针异常

    我试图搜索这个问题 但这个错误看起来与这个错误 https stackoverflow com questions 21866459 android nullpointerexception on webview 我的 google pla
  • 动画结束后更改视图位置

    我开发了一个基于ViewGroup我的问题是我需要在动画结束后保存项目的位置 我打了电话setFillAfter true 在我创建的动画对象中AnimationListener并在其中onAnimationEnd方法调用View layo
  • RecyclerView 适配器的 Kotlin 泛型

    我正在尝试编写一个通用的 recyclerview 适配器 我找到了几个例子 然而 仍然无法弄清楚如何实现通用适配器 我写的代码是 open abstract class BaseAdapter
  • 如何为背景图像添加内边距

    我有一个LinearLayout其中有一个背景图像 一个 9 修补的 png 文件 如何向左和右添加填充 以使背景图像不占据整个宽度 我努力了android paddingLeft and android paddingRight 但这并没

随机推荐