Java 如何在列表视图和应用程序栏之间放置微调器

Java 如何在列表视图和应用程序栏之间放置微调器,java,android,android-spinner,Java,Android,Android Spinner,我目前正在开发一个帮助管理账单的应用程序。我有一个列出账单的活动。我试图在账单列表和顶部标题之间放置一个微调器。是否有办法将微调器置于列表视图的顶部,但位于应用程序栏的下方 这就是应用程序的外观: content\u bill\u list.xml <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schema

我目前正在开发一个帮助管理账单的应用程序。我有一个列出账单的活动。我试图在账单列表和顶部标题之间放置一个
微调器。是否有办法将
微调器置于
列表视图的顶部,但位于应用程序栏的下方

这就是应用程序的外观:


content\u bill\u 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>

驳回此请求 正如评论中所建议的,为什么不使用具有垂直方向的线性布局,并将微调器作为第一个子项(包含高度环绕内容),然后将高度为0dp且布局权重设置为1的listview放在其下方


新提案 看看这个布局。我已经尝试了一个测试应用程序:

<?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>

这是您正在寻找的吗?

如果您将父布局设置为
LinearLayout
?在这种情况下,很容易垂直定位布局。那么
TextView
“dateRangeView”呢?它应该去哪里?同时发布你的布局文件“内容清单”。活动顶部的“dateRangeView”还行。我正在争论,一旦我让选择框(微调器)工作起来,它是否相关。我只是把它放在那里,因为我需要知道账单列表的日期范围。我想未来州的纺纱机会达到这个目的,我不再需要它了。我不明白。我会将AppBarLayout替换为LinearLayout,或者将TextView(dateRangeView)、进度条和包含的内容列表放入微调器已经存在的LinearLayout中,并调整该LinearLayout?我会将所有内容对齐,但在滚动时它会将标题折叠在顶部。我再也没有了。在这个新的设置中,我还可以使用这个功能吗?我认为与原始代码的主要区别在于AppBarLayout下面的线性布局。我想,如果你只从我的帖子中选取这一部分,并保持其他所有事情都像以前一样,它应该会起作用。(同时删除onCreate中的.NoActionBar和代码)
<?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>
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);