【问题标题】:Empty space at the end of RecyclerViewRecyclerView 末尾的空白处
【发布时间】:2018-09-19 07:29:51
【问题描述】:

我使用 LinearLayoutManager 水平显示 RecyclerView 列表

XML

    <android.support.v7.widget.RecyclerView
        android:id="@+id/dailyOffersList"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

代码

dailyOffersList.adapter = DailyOffersListAdapter(dailyOffer)
dailyOffersList.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)

它是项目的 XML,它的宽度为 wrap_content https://codeshare.io/5XnldM

但是列表末尾有空白,只有水平时才会发生,像这样

最后

【问题讨论】:

  • 如果您在行项目 xml 文件中为 match_parent 指定了宽度,那么您需要将其更改为 wrap_content
  • 请添加您的阵列初始化代码和适配器代码。也许有一些空元素或适配器有问题。
  • 您需要按照 piyush 的建议将小部件的宽度更改为 wrap_content
  • 先设置layoutManager,然后设置Adapter并将列表行中的宽度更改为wrap_content
  • @Piyush,我有一个隐藏的加载器元素,它有 match_parent,我已经更改它并且它有帮助,现在它可以工作了,谢谢。

标签: java android android-recyclerview kotlin linearlayoutmanager


【解决方案1】:

将xml中的match_parent改为wrap_content

match_parent 应该填满整个屏幕。

【讨论】:

    猜你喜欢
    • 2015-06-25
    • 2021-06-06
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    相关资源
    最近更新 更多