[英]Android Recycler View - reverse layout inside Constraint Layout
I have a RecyclerView
inside a ConstraintLayout
which is constrained at the top to the parent
and at the bottom by an EditText
.我在
ConstraintLayout
中有一个RecyclerView
,它在顶部被限制到parent
级,在底部被EditText
限制。 This works fine, however as soon as I set the recycler to reverseLayout=true
the first item at the bottom has to be scrolled down to be fully seen if I have more items than the screen can display.这很好用,但是一旦我将回收器设置为
reverseLayout=true
,如果我的项目多于屏幕可以显示,则必须向下滚动底部的第一项才能完全看到。 The preview is exactly how it happens on a real device making me think I am missing something out of the layout.预览正是它在真实设备上发生的方式,让我觉得我在布局中遗漏了一些东西。
NOTE:笔记:
If I remove the bottom constraint to the EditText
in the RecyclerView
from app:layout_constraintBottom_toTopOf="@id/feedMessageInput"
to app:layout_constraintBottom_toBottomOf="parent"
then this problem does not happen, however this is not desirable.如果我从
app:layout_constraintBottom_toTopOf="@id/feedMessageInput"
到app:layout_constraintBottom_toBottomOf="parent"
删除RecyclerView
中EditText
的底部约束,则不会发生此问题,但是这是不可取的。
Xml Layout: Xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/margin_half"
android:layout_marginTop="@dimen/margin_normal"
android:layout_marginEnd="@dimen/margin_normal"
android:layout_marginBottom="@dimen/margin_normal"
android:background="@drawable/shp_rounded_rectangle_transparent_white_05"
tools:context=".ui.messages.feed.FeedFragment">
<ImageView
android:id="@+id/feedEmptyImageView"
android:layout_width="@dimen/icon_size_xxxxxlarge"
android:layout_height="@dimen/icon_size_xxxxxlarge"
android:contentDescription="@string/no_recipients_image"
android:src="@drawable/ic_messages_124dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="@+id/feedRecycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="@dimen/margin_triple"
android:layout_marginEnd="@dimen/margin_half"
android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@id/feedMessageInput"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:reverseLayout="true"
tools:itemCount="5"
tools:listitem="@layout/row_message" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/feedRecipient"
android:layout_width="@dimen/icon_size_medium"
android:layout_height="@dimen/icon_size_medium"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="@dimen/margin_normal"
app:layout_constraintTop_toTopOf="@id/feedMessageInput"
app:layout_constraintBottom_toBottomOf="@id/feedMessageInputView"
app:layout_constraintEnd_toStartOf="@id/feedMessageInputView"
app:layout_constraintHorizontal_bias="0"
tools:src="@tools:sample/avatars" />
<View
android:id="@+id/feedMessageInputView"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/shp_rounded_rectangle_transparent_white_10"
android:maxHeight="@dimen/message_background_input_max_height"
app:layout_constraintBottom_toBottomOf="@id/feedMessageInput"
app:layout_constraintEnd_toEndOf="@id/feedMessageInput"
app:layout_constraintStart_toStartOf="@id/feedMessageInput"
app:layout_constraintTop_toTopOf="@id/feedMessageInput" />
<EditText
android:id="@+id/feedMessageInput"
style="@style/MessagingEditText.NoUnderline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_normal"
android:importantForAutofill="no"
android:inputType="textMultiLine"
android:maxLength="@integer/max_message_length"
android:padding="@dimen/margin_half"
android:textSize="@dimen/message_input_text_size"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/feedSelectTemplate"
app:layout_constraintHeight_max="@dimen/message_background_input_max_height"
app:layout_constraintHeight_min="@dimen/message_background_input_height"
app:layout_constraintStart_toEndOf="@id/feedRecipient"
app:layout_constraintTop_toBottomOf="@id/feedRecycler"
tools:hint="Send message to +447445343433"
tools:ignore="LabelFor" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/feedSendMessage"
style="@style/MessagingFloatingActionButton.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin_normal"
android:src="@drawable/ic_sms_message_send_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/feedSelectTemplate"
app:layout_constraintTop_toTopOf="@id/feedMessageInput" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/feedSelectTemplate"
style="@style/MessagingFloatingActionButton.Small.Contrast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin_normal"
android:src="@drawable/ic_sms_message_template_24dp"
app:layout_constraintEnd_toStartOf="@id/feedSendMessage"
app:layout_constraintStart_toEndOf="@id/feedMessageInput"
app:layout_constraintTop_toTopOf="@id/feedMessageInput" />
</android.support.constraint.ConstraintLayout>
Current Incorrect preview when multiple rows that scroll off the top and bottom - which is incorrect:当前不正确的预览,当多行从顶部和底部滚动时 - 这是不正确的:
How I expect reverseLayout=true
to work no matter how many rows scroll off the top:无论从顶部滚动多少行,我都希望
reverseLayout=true
起作用:
Any help with something I may have missed would be appreciated.任何我可能错过的东西的帮助将不胜感激。
According to the documentation for ConstraintLayout :根据ConstraintLayout的文档:
Important: MATCH_PARENT is not recommended for widgets contained in a ConstraintLayout.
重要提示:不建议将 MATCH_PARENT 用于 ConstraintLayout 中包含的小部件。 Similar behavior can be defined by using MATCH_CONSTRAINT with the corresponding left/right or top/bottom constraints being set to "parent".
可以通过使用 MATCH_CONSTRAINT 来定义类似的行为,并将相应的左/右或上/下约束设置为“父”。
Why does this sort of work?为什么这样的工作? My guess is that it is not really supported but has not been disabled and is probably not tested.
我的猜测是它并没有得到真正的支持,但没有被禁用,可能没有经过测试。 The short answer is to use
match_constraints
( 0dp
) exclusively and to avoid match_parent
at all times when it comes to ConstraintLayout .简短的回答是仅使用
match_constraints
( 0dp
) 并在涉及ConstraintLayout时始终避免match_parent
。
Faced with the same issue.面临同样的问题。 It looks like ConstraintLayout issue (still is in beta).
它看起来像 ConstraintLayout 问题(仍处于测试阶段)。 I've rewritten xml layout to use LinearLayout and it works for me.
我已经重写了 xml 布局以使用 LinearLayout,它对我有用。 But still waiting for the fix from Google.
但仍在等待谷歌的修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.