android - 如何替换旧 API<21 中的 NestedScrollView?

标签 android android-layout android-fragments android-toolbar

我的布局 fragment 有问题:

<android.support.v4.widget.NestedScrollView 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:layout_gravity="fill_vertical"
    android:clipToPadding="false"
    android:fillViewport="true"
    android:nestedScrollingEnabled="true" <!-- this don't work with api levels older than 21 -->
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout 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:orientation="vertical"
        tools:context=".MainActivity">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:id="@+id/elements" />
    </LinearLayout>

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

当用户滚动 fragment 时,我需要消失/出现工具栏。 此方法不适用于 API 19(例如):你会用这个 Android 设备做什么?

最佳答案

这在 API 21 下的 XML 中不起作用,但相应的代码在支持库中可以正常工作:

recyclerView.setNestedScrollingEnabled(true);

关于android - 如何替换旧 API<21 中的 NestedScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39837499/

相关文章:

java - 正面点击时 Android 对话框崩溃

Android Intent.ACTION_VIEW 基本身份验证

android - 滚动到列表底部时隐藏 FloatingAction 项?

java - 单击抽屉导航的项目不会打开 fragment

Fragment中RecyclerView的Android单元测试用例

android - 如何跨多个应用程序共享服务并检查它是否已经运行?

Android,如何正确制作透明状态栏

Android动态添加的按钮不适合布局

java - 如何隐藏菜单栏但仍通过菜单按钮访问它

java - 在 Fragment 中显示 RecyclerView