在底部对齐 RecyclerView 中的项目

her*_*mt2 6 android android-layout android-xml android-recyclerview android-constraintlayout

我有一个 a 的RecyclerView内部,ConstraintLayout其顶部从a的底部开始textView,其底部向下延伸到父级。我希望此中的项目RecyclerView默认为RecyclerView. 我尝试添加gravity="bottom"并且还尝试了与foregroundGravity和相同的事情layout_gravity。我还尝试添加layout_gravity="bottom"到我的recyclerView项目的布局。尽管如此, 中的所有项目recyclerView仍然默认为顶部。我能做些什么来确保物品在底部吗?这是xml:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/my_tv"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="needed to unlock next coupon"
        android:textColor="@color/gray"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/irrelevant_tv"
        android:layout_marginTop="@dimen/spacing_tiny"
        android:gravity="center"
        />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="@dimen/spacing_xl"
        android:paddingTop="@dimen/spacing_large"
        android:overScrollMode="always"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        app:layout_constraintTop_toBottomOf="@id/my_tv"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

我不想做wrap_contentrecyclerView任何,因为否则就不是scrollable(我一直在这3项recyclerView,并根据用户的显示设置,recyclerView可以得到被推离屏幕,这需要我可以滚动)

小智 13

您可以使用该方法LinearLayoutManager#setStackFromEnd(boolean)。然后您的项目将从视图底部开始呈现。

请参阅文档