首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LinearLayoutManager在卡片之间创建空间

LinearLayoutManager在卡片之间创建空间
EN

Stack Overflow用户
提问于 2016-03-02 23:23:05
回答 1查看 79关注 0票数 0

我目前正在使用一个RecyclerView来显示一个卡片列表。它在ListViewArrayListAdapter上运行得很好,但是现在发生了一些奇怪的事情。

当第一次加载列表时,将正确显示3张显示的第一张卡片。但是那些没有显示出来的在它们下面都有一个很大的空间。

它与LayoutManager有关,正如to所说,它是一个实体,负责管理要显示什么和如何显示它。

在我的例子中,我使用的是LinearLayoutManager

以下是我在Fragment中初始化的一些代码

代码语言:javascript
复制
layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
listAdapter = new EventsListAdapter(events);
recyclerView.setAdapter(listAdapter);
recyclerView.setLayoutManager(layoutManager);

下面是RecyclerView布局:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.RecyclerView
    android:id="@+id/events_list_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" />
</RelativeLayout>

最后我的CardView声明

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/event_row_cardview">
    ...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-03 01:20:46

我找到了问题的根源。

我的CardView被包装在一个带有属性android:layout_height="match_parent"LinearLayout中,所以每次呈现它时,它都占据了屏幕的整个高度。

我通过将属性更改为android:layout_height="wrap_content"来修正它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35760242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档