首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用垂直GridLayoutManager将RecyclerView项水平居中

如何使用垂直GridLayoutManager将RecyclerView项水平居中
EN

Stack Overflow用户
提问于 2016-07-28 07:35:42
回答 2查看 49.9K关注 0票数 64

我有一个使用GridLayoutManager的垂直RecyclerView。我希望每一列都居中,但所有列都从左侧开始。在下面的图片中,你可以看到我在说什么。我使用丑陋的配色方案来说明列和背景。绿色是RecyclerView中每个项目的背景,红色是RecyclerView本身的背景:

http://imgur.com/a/J3HtF

我使用以下命令进行设置:

代码语言:javascript
复制
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));

下面是column_item.xml:

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

    <ImageView
        android:id="@+id/movie_column_photo"
        android:layout_width="80dp"
        android:layout_height="120dp"/>

    <TextView
        android:id="@+id/movie_column_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

下面是recyclerview:

代码语言:javascript
复制
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/company_details_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical">
    </android.support.v7.widget.RecyclerView>
</LinearLayout>
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38624843

复制
相关文章

相似问题

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