gpt4 book ai didi

java - SwipeRefreshLayout 不遵守约束

转载 作者:行者123 更新时间:2023-11-29 08:26:08 29 4
gpt4 key购买 nike

我有一个 SwipeRefreshLayout,其中包含用于聊天 Activity 的 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 仍然占据了整个屏幕并且消息出现在消息输入后面:

enter image description here

是否需要特殊类型的约束才能起作用?

最佳答案

SwipeRefreshLayout 的高度更改为 0dp

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="0dp"

为什么?

根据 documentation :

You can set the view size to a ratio such as 16:9 if at least one of the view dimensions is set to "match constraints" (0dp).

还有

Note: You cannot use match_parent for any view in a ConstraintLayout. Instead use "match constraints" (0dp).

关于java - SwipeRefreshLayout 不遵守约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52909400/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com