CoordinatorView Scroll无法正常工作

时间:2016-07-06 20:08:44

标签: android scrollview

我正在使用android.support.design.widget.CoordinatorLayoutandroid.support.design.widget.AppBarLayout一起在滚动浏览listView时尝试在我的应用上实现隐藏工具栏。但是,滚动时Scroll dos不起作用。下面是我的主视图的xml。 我错过了什么吗?

我还为包含listView的片段添加了布局xml。

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context="com.mcgowan.timetable.itsligotimetables.MainActivity">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="5dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="?attr/listPreferredItemHeight"
                android:layout_gravity="left"
                android:src="@drawable/timetable_logo"
                app:layout_scrollFlags="scroll|enterAlways" />
        </android.support.v7.widget.Toolbar>

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

    <FrameLayout 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:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

片段XML

<FrameLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="0dp"
android:paddingRight="0dp"
tools:context=".TimeTableFragment">


<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/listview_timetable" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:text="@string/no_info_available"
    android:paddingLeft="@dimen/activity_vertical_margin"
    android:paddingRight="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:id="@+id/listview_empty" />

Ugur B解决方案 Implementation from Solution

预期显示 Expected display before scroll

1 个答案:

答案 0 :(得分:0)

正如@EugeneH所说,Coordinatorlayout只与RecyclerView和NestedScrollView兼容。

15

编辑: 因此,您不需要使用CollapsingToolbarLayout只使用静态appbar并使用listview中的recyclerview。

相关问题