gpt4 book ai didi

android - CoordinatorLayout 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:05:28 25 4
gpt4 key购买 nike

我正在尝试从新发布的 Android Design Support Library 中实现 CoordinatorLayout并且我根据示例 here 在我的 XML 布局中使用了以下代码:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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

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

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

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

但是,当我向下 ScrollView 时,操作栏不会隐藏。我不明白为什么这不起作用。

编辑:据我所知,CoordinatorLayout 不适用于 ListView/GridView/ScrollViews 并且仅适用于 RecyclerViewNestedScrollView。不幸的是,简单地切换到其中一种 View 对我来说是不可能的,所以我仍在寻找解决方案。

最佳答案

当前并非所有 View 都具有 CoordinatorLayout 的预期行为。

您的 View 应该实现 NestedScrollView 接口(interface)并且必须处理嵌套的滚动事件。

RecyclerViewNestedScrollView(版本 22)支持此行为。但是,您也可以使用 AbsListView(ListViewGridView),但仅限于 API21+。

只需添加如下内容:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
listView.setNestedScrollingEnabled(true);
}

关于android - CoordinatorLayout 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30561037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com