【发布时间】:2018-04-03 01:52:33
【问题描述】:
我有一个显示项目列表的 RecyclerView 视图。页面顶部是一个操作栏,底部是一个用于输入文本的 LinearLayout 和一个带有列表项区域的按钮(单击时扩展)中间。我试图将 RecyclerView 高度的大小限制为剩余的可用高度(工具栏下方和线性布局上方)。
不幸的是,顶部和底部的项目似乎位于底部的工具栏和布局下方,无法看到。我设法通过添加android:paddingTop="?attr/actionBarSize 来欺骗顶部,但我知道这不是正确的做法。滚动正常工作。
我不明白为什么即使设置了约束也会发生这种情况?如何将回收站视图限制在内部区域?
<?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"
tools:context="kevcon.ie.cloaked.SendMessage">
<!-- Might remove to suit api level-->
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.v7.widget.RecyclerView
android:paddingTop="?attr/actionBarSize"
android:id="@+id/recycler_view_inbox_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/my_toolbar"
app:layout_constraintBottom_toTopOf="@id/layout_chatbox"
/>
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:background="@color/colorLightGrey"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/layout_chatbox"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/my_toolbar" />
<LinearLayout
android:id="@+id/layout_chatbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minHeight="48dp"
android:background="@color/colorLightGrey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<EditText
android:id="@+id/edit_message"
android:hint="@string/send_message_hint"
android:background="@android:color/transparent"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:maxLines="6" />
<Button
android:id="@+id/button_sms_send"
android:layout_width="64dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="@color/colorAccent"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="@string/send_button_text"
android:textSize="14sp"
/>
</LinearLayout>
【问题讨论】:
标签: android xml android-recyclerview android-constraintlayout