CoordinatorLayout/AppBarLayout ExpandableListView在屏幕外呈现 [英] CoordinatorLayout/AppBarLayout ExpandableListView being rendered off screen

查看:130
本文介绍了CoordinatorLayout/AppBarLayout ExpandableListView在屏幕外呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用CoordinatorLayout和AppBarLayout时还有更多问题.

Yet more problem in using CoordinatorLayout and AppBarLayout.

我正在尝试实现以下基本功能:向下滚动时使工具栏滚动离开屏幕,向上滚动时使工具栏回到屏幕.

I'm trying to achieve the basic functionality of having the Toolbar scroll off screen when scrolling down and coming back on screen when scrolling up.

但是,我当前的设置显示了一个问题:不仅工具栏没有滚动,而且ListView似乎在底部的屏幕上呈现.好像它已经被AppBarLayout的高度偏移了.

However, my current set up is showing a problem: Not only is the Toolbar not scrolling off, the ListView seems to be rendering off screen at the bottom. It's almost as if it's been offset by the AppBarLayout height.

以下是描述问题的gif文件,请注意,最后一个项目也被切断,并且ScrollBar不在屏幕上:

Here is a gif describing the issue, note that the final item is cut off also the ScrollBar is off screen:

我的布局很标准:

<?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"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent"
                                                 android:background="@color/background">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="@color/orange"
            app:layout_scrollFlags="scroll|enterAlways"/>

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


    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeToRefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <ExpandableListView
            android:id="@+id/listView"
            android:groupIndicator="@android:color/transparent"
            android:layout_width="match_parent"
            android:dividerHeight="0px"
            android:layout_height="match_parent"/>
    </android.support.v4.widget.SwipeRefreshLayout>

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

推荐答案

CoordinatorLayout仅与RecyclerView或NestedScrollView一起使用.尝试将您的ExapandableListView封装在NestedScrollView内,或使用以下代码将NestedScrollingEnable用于ExpandableListView.

CoordinatorLayout only works with RecyclerView or NestedScrollView.Try Wrapping your ExapandableListView inside NestedScrollView or use the below code to make NestedScrollingEnable for ExpandableListView.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     expandablelistView.setNestedScrollingEnabled(true);
}else {
     CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mSwipeLayout.getLayoutParams();
     params.bottomMargin = heightOfAppBarCompat;
     mSwipeLayout.setLayoutParams(params);
}

编辑您可以使用else语句按预期在21年前进行滚动工作.

Edit You can make scrolling work as expected pre-21 with the else statement.

这篇关于CoordinatorLayout/AppBarLayout ExpandableListView在屏幕外呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆