java - SwipeRefreshLayout 不遵守约束
问题描述
我有一个 SwipeRefreshLayout,其中包含一个用于聊天活动的 RecyclerView。我将其底部限制在屏幕底部的线性布局的顶部:
<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="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorPrimaryDark"
android:paddingLeft="0dp"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="0dp"
android:paddingBottom="0dp"
tools:context="org.andrewedgar.theo.ChatRoomActivity">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/listFooter"
app:layout_constraintBottom_toTopOf="@+id/listFooter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/chatRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:layout_constraintBottom_toTopOf="@+id/listFooter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/listFooter"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="@drawable/custom_border"
android:gravity="bottom"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<EditText
android:id="@+id/messageInput"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:ellipsize="start"
android:gravity="center"
android:hint="@string/prompt_msg"
android:imeActionLabel="@string/action_send"
android:imeOptions="actionUnspecified"
android:inputType="textCapSentences|textAutoCorrect"
android:maxLines="2"
android:textColor="@color/white"
android:textColorHint="@color/hintColor"
android:importantForAutofill="no" tools:targetApi="o"/>
<ImageButton
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:contentDescription="@string/action_send"
android:padding="10dp"
android:src="@android:drawable/ic_menu_send" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
..但 SwipeRefreshLayout 仍然占据整个屏幕,并且消息出现在消息输入后面:
是否需要特殊类型的约束才能使其起作用?
解决方案
将高度更改SwipeRefreshLayout
为 0dp
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="0dp"
为什么?
根据文档:
如果至少有一个视图尺寸设置为“匹配约束”(0dp),您可以将视图尺寸设置为 16:9 等比例。
还
注意:您不能
match_parent
用于ConstraintLayout
. 而是使用“match constraints
”(0dp)。
推荐阅读
- laravel - 如何在 Laravel 中获取特定字符串的记录?
- python - Pyspark:pyarrow.lib.ArrowInvalid:'utf-32-le'编解码器无法解码位置 0-3 中的字节:代码点不在范围内(0x110000)
- java - 未报告 Java 错误行号且不允许调试
- apache-kafka - 如何在 Quarkus 中的多个服务之间共享一个 kafka 连接器及其配置?
- react-native - 如何在 react-native 中将 expo-blur 添加到模态中
- reactjs - React Material Ui 和 React 路由器
- python - 绘制 For Iteration 的结果
- linux - 删除除第一次出现的 Pattern 之外的所有匹配行
- python - 为什么这个 curl 命令有效,但我通过 python 的 post 请求无效?
- python - Python:string.rfind() 不使用反斜杠 ('\')