Android 回收视图项目左对齐

Android 回收视图项目左对齐,android,android-recyclerview,Android,Android Recyclerview,我在FoodCardFragment中有一个tags_框架,可以找到它的布局,用于在中显示RecyclerView。TagsFragment的布局很简单: <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/recycler_view" android:layout_width="matc

我在FoodCardFragment中有一个tags_框架,可以找到它的布局,用于在中显示RecyclerView。TagsFragment的布局很简单:

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start" />
RecyclerView使用StaggedGridLayoutManager或LinearLayoutManager。但是,正如您从我的cardview的中间看到的,这个由圆角矩形组成的RecyclerView使用StaggedGridLayoutManager,并且它居中。实际上,在我使用LinearLayoutManager的另一个活动中,它也是以中心为中心的

如何将其与卡的左起点对齐

您可以在fragment_tags.xml中尝试:


将换行内容用于布局宽度。

之所以会出现这种情况,是因为您将框架布局约束为两侧的父级,并将宽度设置为匹配父级。您有更多选项,一个是将重力开始设置为framelayout,或者将framelayout的宽度设置为wrap_内容,将constraint仅设置为开始。

在问题中发布代码,而不是链接到它。尝试将constraint layout中的layout_宽度更改为320dp或wrap_内容
<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/recycler_view"
    android:layout_width="wrap_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start" />