Android 再循环流重力

Android 再循环流重力,android,android-recyclerview,Android,Android Recyclerview,我有一个recylcler视图,但它似乎没有实现setGravity方法 我的列表是水平对齐的,但我需要它居中。我该怎么做 fragment\u my\u zone\u item\u controlled.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr

我有一个recylcler视图,但它似乎没有实现setGravity方法

我的列表是水平对齐的,但我需要它居中。我该怎么做

fragment\u my\u zone\u item\u controlled.xml

<?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="match_parent"
    android:background="@color/dark_grey">

    <FrameLayout
        android:id="@+id/fragment_my_zone_item_controlled_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/fragment_my_zone_item_controlled_tabs"
        android:layout_marginBottom="12dp"
        android:layout_marginTop="12dp" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/fragment_my_zone_item_controlled_tabs"
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:background="@color/action_bar_color"
        android:scrollbars="none" />

</RelativeLayout>

这就是它的样子,我需要它居中


谢谢大家

我知道这是一个很晚的答案,可能是其他人从中得到了帮助,所以请尝试这样添加

 <android.support.v7.widget.RecyclerView
        android:id="@+id/fragment_my_zone_item_controlled_tabs"
        android:layout_width="wrap_content"
        android:layout_height="44dp"
        android:layout_centerHorizontal="true"
        android:background="#dddddd"
        android:scrollbars="none" />


add
android:layout\u centerHorizontal=“true”
方法

如果其他答案对您没有帮助,我在
RecyclerView
中遇到了一个问题,内容没有得到有效包装,这导致版面被迫放在一个角落或另一个角落

我的答案是创建一个扩展了
LinearLayoutManager
的自定义类。您可以尝试这样做,然后通过编程设置重力

这是我的链接,也是我得到答案的帖子。

(如果有人在寻找像我这样的答案),我尝试了这两种解决方案,但都不适用于我,以下是我所做的。我计算了屏幕宽度和我的视图宽度,然后在我的
RecyclerView.ViewHolder
中,我在我视图的左侧添加了边距(在我的情况下,这是一个比率)


这是一个凌乱的解决方案,但我找不到另一个

LazyFinder解决方案,但以防万一,如果您想为RV使用不同的背景颜色,请将其添加到FrameLayout并将其重心设置为中心

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorWhite">

        <android.support.v7.widget.RecyclerView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            />

</FrameLayout>


另一个关键变化是将
android:layout\u width
设置为
wrap\u content
。这将
RecyclerView
集中在其父级-
RelativeLayout
中。但这对回收商的项目或回收商的宽度为
match\u parent
时没有影响。回收商视图没有
layout\u center\u horizon
<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorWhite">

        <android.support.v7.widget.RecyclerView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            />

</FrameLayout>