android - 使用 CollapsingToolbarLayout 时 ListView 不适合底部

标签 android listview android-collapsingtoolbarlayout

我在我的应用中使用了不同的 fragment 。一个 fragment 包含 RecyclerView,其他 fragment 包含 ListView 和 GridView。但是 ListView 和 GridView 不适合底部屏幕。如何解决这个问题?谢谢。

P.S:对不起我的英语。

enter image description here

Activity 布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|enterAlways">

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

            </android.support.v7.widget.Toolbar>

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

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/app_nav_header_main"
    app:menu="@menu/main_drawer" />

</android.support.v4.widget.DrawerLayout>

标签布局:

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include
    layout="@layout/layout_please_wait"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:elevation="2dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:tabIndicatorColor="@android:color/white" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

<include
    layout="@layout/layout_no_internet"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</ViewFlipper>

标签布局:

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    layout="@layout/layout_please_wait" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="@dimen/grid_padding"
    android:paddingRight="@dimen/grid_padding">

    <Spinner
        android:id="@+id/dateSpiner"
        style="?android:attr/spinnerItemStyle"
        android:layout_width="@dimen/spinner_width"
        android:layout_height="wrap_content"
        android:layout_gravity="right" />

    <GridView
        android:id="@+id/billboardList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:columnWidth="@dimen/grid_item_column_width"
        android:gravity="center"
        android:horizontalSpacing="@dimen/grid_horizontal_spacing"
        android:numColumns="auto_fit"
        android:scrollbars="none"
        android:stretchMode="columnWidth"
        android:verticalSpacing="@dimen/grid_vertical_spacing">

    </GridView>
</LinearLayout>

<include
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    layout="@layout/layout_no_internet" />

</ViewFlipper>

最佳答案

使用 com.android.support:design:25.0.1 时,我遇到了类似的问题,即在使用 CollapsingToolbarLayout 时, View 底部不会完全向上滚动>嵌套 ScrollView 。当设备旋转或打开/关闭键盘时问题消失,对我来说这表明支持库错误。

我通过摆弄 View 来触发一些 fragment 刷新来解决它。

onViewCreated中我添加了

 Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override
            public void run() {
                mSomeViewInsideNestedScrollView.setVisibility(View.GONE);
                mSomeViewInsideNestedScrollView.setVisibility(View.VISIBLE);
            }
        });

将操作放在 UI 线程队列的末尾。

我意识到这看起来像一个丑陋的 hack,但它解决了我的问题。

关于android - 使用 CollapsingToolbarLayout 时 ListView 不适合底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37356172/

相关文章:

android - onBackPressed 和 android 中的线程

android - 性能问题 - ListView、TextView,每个子项中都有一个 Spanned 输入

android - 如何使折叠工具栏不完全折叠?

java - 如何从android中的按钮重定向到另一个应用程序?

android - 如何更新可组合函数内的 RecyclerView 的数据?

java - RatingBar 不显示准确的评分

android - 如何在折叠工具栏布局下添加 viewpager 和 tablayout

java - 如何获得折叠工具栏布局的最大垂直偏移

java - 添加新 Activity 期间 Eclipse 错误

android - Scrolling Activity 中的 ListView 仅显示单个项目