【发布时间】:2018-05-12 08:43:33
【问题描述】:
我在ConstraintLayout 内部有一个RecyclerView,其顶部从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>
我也不想在recyclerView 上做wrap_content,否则它不是scrollable(我在这个recyclerView 中总是有3 个项目,并且根据用户的显示设置,@987654337 @ 可以被推离屏幕,这需要我能够滚动)
【问题讨论】:
-
使用 LinearLayout 进行更好的控制
-
你能把你所有的xml代码粘贴到这里吗?所以我可以给你精炼的代码。
-
如果我使用线性布局,那么我将无法将回收器视图拉伸到底部,这是我想要做的以使其可滚动。否则我必须做 wrap_content
-
那么我可以看看你需要的布局吗,任何屏幕?
-
您应该使用 Ctrl+K 或 ⌘+K 来正确格式化您的源代码块。
标签: android android-layout android-recyclerview android-xml android-constraintlayout