Как поставить счетчик между списком и панелью приложений - PullRequest
0 голосов
/ 30 августа 2018

В настоящее время я работаю над приложением, которое поможет управлять счетами. У меня есть деятельность, которая перечисляет счета. Я пытаюсь поместить spinner между списком счетов и заголовком вверху. Есть ли способ поместить spinner так, чтобы он находился вверху listView, но под панелью приложения ??

Вот как выглядит приложение:

enter image description here

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <TextView
        android:id="@+id/dateRangeView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/date_range"
        android:textColor="@android:color/background_light"
        android:textSize="24sp"
        android:textStyle="bold"
        tools:textAlignment="center"
        tools:textColor="@android:color/white" />

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBarBillList"
        android:progressDrawable="@drawable/circular_progress_bar"
        android:layout_gravity="center" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_anchor="@+id/app_bar"
        android:id="@+id/bill_dates"
        app:layout_anchorGravity="bottom|center">

        <Spinner
            android:id="@+id/spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_marginHorizontal="16dp"
            android:background="@android:color/background_light"
            android:entries="@array/date_arrays"
            android:prompt="@string/bill_date_prompt"
            android:spinnerMode="dialog"
            app:layout_anchor="@+id/listBillView"
            app:layout_anchorGravity="top|right" />
    </LinearLayout>

    <include layout="@layout/content_bill_list" app:layout_anchor="@+id/bill_dates" />

</android.support.design.widget.CoordinatorLayout>

content_bill_list.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.yourdirectlink.ydlcms.BillListActivity"
    tools:showIn="@layout/activity_bill_list">
    <ListView
        android:id="@+id/listBillView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" >
    </ListView>
</android.support.v4.widget.NestedScrollView>

1 Ответ

0 голосов
/ 31 августа 2018

ОТКЛОНЯЕТ ЭТО

Как предлагается в комментариях, почему бы не использовать LinearLayout с вертикальной ориентацией и поместить спиннер в качестве первого дочернего элемента с высотой wrap_content, а затем под ним список просмотра с высотой 0dp и layout_weight, установленным в 1


НОВОЕ ПРЕДЛОЖЕНИЕ

Посмотрите на этот макет. Я уже пробовал в тестовом приложении:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:toolbarId="@id/toolbar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"/>
        <!--app:popupTheme="@style/AppTheme.PopupOverlay" />-->

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<LinearLayout
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/dateRangeView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/date_range"
        android:textColor="@android:color/background_light"
        android:textSize="24sp"
        android:textStyle="bold"
        tools:textAlignment="center"
        tools:textColor="@android:color/white" />

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_marginHorizontal="16dp"
        android:background="@android:color/background_light"
        android:entries="@array/date_arrays"
        android:prompt="@string/bill_date_prompt"
        android:spinnerMode="dialog"
        app:layout_anchor="@+id/listBillView"
        app:layout_anchorGravity="top|right" />

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBarBillList"
        android:layout_gravity="center" />


    <include
        layout="@layout/content_bill_list"
        app:layout_anchor="@+id/bill_dates"/>
</LinearLayout>

</android.support.design.widget.CoordinatorLayout>

Я должен комментировать всплывающую тему, потому что у меня ее нет.

Также вам нужно использовать тему с .NoActionBar , потому что вы поддерживаете панель действий, а в Activity, содержащей этот макет, вам нужно вызвать:

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Это то, что вы ищете?

...