【发布时间】:2018-03-26 10:25:35
【问题描述】:
我在Android Developers 上读到,ConstraintLayout 可用于为应用程序设计响应式布局。有一个父 ConstraintLayout,其中包含一个工具栏和两个其他 ConstraintLayout。第一个子 ConstraintLayout 将充当我的 ListView 的空视图。第二个 ConstraintLayout 包含我的列表视图和一个浮动操作按钮。目前,列表视图出现在工具栏下方,而不是下方。同样如屏幕截图所示,浮动操作按钮出现在可见区域之外。
请看下面的截图:
这是我的布局代码:
<?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"
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<android.support.constraint.ConstraintLayout
app:layout_constraintTop_toBottomOf="@id/toolbar"
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize">
<TextView
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/tv_empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/list_is_empty"
android:textSize="@dimen/large_text"
android:textStyle="bold"
/>
<ImageView
android:id="@+id/iv_empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tv_empty_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:contentDescription="@string/list_is_empty"
android:src="@drawable/emptybox" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/main_area"
android:layout_marginTop="50dp"
android:layout_marginBottom="?actionBarSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constraintBottom_toBottomOf="parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="?attr/actionBarSize"
android:layout_marginLeft="@dimen/margin_side"
android:layout_marginStart="@dimen/margin_side"
android:layout_marginRight="@dimen/margin_side"
android:layout_marginEnd="@dimen/margin_side"
android:layout_marginTop="?attr/actionBarSize"
/>
<android.support.design.widget.FloatingActionButton
android:layout_below="@+id/listview"
android:id="@+id/fab"
android:layout_width="@android:dimen/notification_large_icon_width"
android:layout_height="@android:dimen/notification_large_icon_height"
android:layout_gravity="end|bottom"
android:src="@drawable/plus"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
您没有将
constraints添加到两个ConstraintLayouts。
标签: android listview android-constraintlayout