首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LinearLayoutManager (LinearLayoutManager.HORIZONTAL)不工作

LinearLayoutManager (LinearLayoutManager.HORIZONTAL)不工作
EN

Stack Overflow用户
提问于 2019-10-23 17:46:58
回答 1查看 787关注 0票数 0

我想使用水平卷轴回收器。

对于这一点,我使用LinearLayoutManager (LinearLayoutManager.HORIZONTAL),这是可行的,但是对于这些项目获得了不同的缩进。

截图- https://i.stack.imgur.com/Mqp8A.png

碎片的布局:

代码语言:javascript
复制
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list_related"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        tools:listitem="@layout/item_2_lenta"/>
</LinearLayout>

项目布局:

代码语言:javascript
复制
<com.google.android.material.card.MaterialCardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardCornerRadius="4dp"
    app:cardBackgroundColor="#ff0">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        ...
        </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

UPD

创建layoutManager

代码语言:javascript
复制
vRelatedStub.setOnInflateListener((viewStub, sView) -> {
    vLabelRelated = sView.findViewById(R.id.label_related);
    vListRelated = sView.findViewById(R.id.list_related);
    vLoaderRelated = createLoaderView(sView, mAdapterRelated);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(),
                LinearLayoutManager.HORIZONTAL, false);
    vListRelated.setLayoutManager(layoutManager);
    vListRelated.setAdapter(mAdapterRelated);
});
vRelatedStub.inflate();
EN

回答 1

Stack Overflow用户

发布于 2019-10-24 16:09:41

在我的代码中发现了错误。问题是,我要求在绑定的第一个项目的保证金,这仍然是从垂直线性管理器。

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

https://stackoverflow.com/questions/58528401

复制
相关文章

相似问题

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