Mit ListView-innen ConstraintLayout

Habe ich gelesen, auf Android-Entwickler, dass ConstraintLayout kann verwendet werden, um das design einer responsive layout für eine Anwendung. Es besteht eine Eltern-ConstraintLayout die Häuser eine Symbolleiste und zwei andere ConstraintLayouts. Das erste Kind ConstraintLayout ist handeln als leere Ansicht für meine ListView. Die zweite ConstraintLayout hält meine listview und ein floating-action-button. Derzeit ist die listview erscheint unter der Symbolleiste, anstatt darunter. Auch wie man in dem screenshot sieht, wird die floating-action-button erscheint außerhalb sichtbaren Bereichs.

Siehe screenshot unten:

Mit ListView-innen ConstraintLayout

- Und das ist das app-layout, wenn die Liste leer ist:

Mit ListView-innen ConstraintLayout

Dies ist der code für mein layout:

<?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>
  • Hinzufügen Sie nicht constraints zwei ConstraintLayouts.
InformationsquelleAutor codezombie | 2017-10-14
Schreibe einen Kommentar