aed*_*777 1 java android android-studio
我有一个 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>
Run Code Online (Sandbox Code Playgroud)
..但是 SwipeRefreshLayout 仍然占据整个屏幕并且消息出现在消息输入后面:
这是否需要特殊类型的约束才能起作用?
将 的高度更改SwipeRefreshLayout为 0dp
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="0dp"
Run Code Online (Sandbox Code Playgroud)
为什么?
根据文档:
如果至少有一个视图尺寸设置为“匹配约束”(0dp),您可以将视图大小设置为一个比率,例如 16:9。
还
注意:您不能
match_parent用于ConstraintLayout. 而是使用“match constraints”(0dp)。
| 归档时间: |
|
| 查看次数: |
1431 次 |
| 最近记录: |