我尝试在ChatView中首先显示最后一项。不幸的是app:stackFromEnd =“true”函数不起作用,视图显示第一项默认值。我在XML布局中执行了以下操作:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_above="@+id/sendlayout"
android:layout_marginBottom="20dp"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleview"
app:stackFromEnd = "true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager">
</android.support.v7.widget.RecyclerView>
答案 0 :(得分:0)
尝试使用app:layoutManager="android.support.v7.widget.LinearLayoutManager"
而不只是app:layoutManager="LinearLayoutManager"
,并确保您不以编程方式设置它:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleview"
app:stackFromEnd = "true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
答案 1 :(得分:0)
由于LinearLayoutManager覆盖了stackFromEnd设置,因此您必须在LinearLayoutManager中设置stackFromEnd:
recycleview.layoutManager = LinearLayoutManager(context).apply {
orientation = LinearLayoutManager.VERTICAL
stackFromEnd = true
// Apply other LinearLayoutManager settings
}