I have a RecyclerView
inside of a ConstraintLayout
whose top starts at the bottom of a textView
, and whose bottom stretches down to the parent. I want the items in this RecyclerView
to default to the bottom of the RecyclerView
. I tried adding gravity="bottom"
and also tried the same thing with foregroundGravity
and layout_gravity
. I also tried adding layout_gravity="bottom"
to my recyclerView
item's layout. Still, all the items in the recyclerView
continues to default to the top. Is there anything i can do to make sure the items are at the bottom? Here is the 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>
I don't want to do wrap_content
on recyclerView
either, because otherwise it is not scrollable
(I always have 3 items in this recyclerView
, and based on the user's display settings, the recyclerView
can get pushed off the screen, which requires me to be able to scroll)
You can use the method LinearLayoutManager#setStackFromEnd(boolean)
. Then your items will be rendered starting from bottom of view.
See the docs .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.