草庐IT

android - API 19 ScrollView 没有动量

coder 2024-07-03 原文

我在 CoordinatorLayout 中有一个 NestedScrollView,它包含一个 recyclerView。整个 fragment 很长,没有滚动动量,我不确定我能做些什么来修复它。我以前在使用更高版本的 Android 时遇到过这个问题,并且能够包含

android:nestedScrollingEnabled="false"

解决我的问题。但是,这是在 api 21 中添加的,我的项目支持 19+。我的应用程序在 api 19 设备的这个 fragment 上仍然没有动力。

下面是我的xml:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@color/primary_color"
    android:fitsSystemWindows="true">

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">

    <android.support.percent.PercentRelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:nestedScrollingEnabled="false">

        <ImageView
                android:id="@+id/logo"
                android:src="@drawable/logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/profile_margin_medium_huge"
                android:layout_marginBottom="46dp"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_alignParentEnd="true"/>

        <TypefaceTextView
                android:id="@+id/textview_title"
                android:layout_below="@id/logo"
                android:text="@string/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                style="@style/myStyle"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:layout_marginBottom="16dp"
                android:layout_alignParentLeft="true"/>

        <TypefaceTextView
                android:id="@+id/textview_byline"
                android:text="@string/byline"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                style="@style/myStyle"
                android:layout_below="@id/textview_title"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:layout_marginBottom="40dp"/>

        <RadioGroup
                android:id="@+id/radiogroup_filter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_below="@id/textview_byline"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:layout_marginBottom="@dimen/activity_vertical_margin">

            <TypefaceRadioButton
                    android:id="@+id/button_filter_new"
                    android:text="@string/filter_new"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    style="@style/buttonStyleRadio"
                    android:theme="@style/ButtonSecondary"
                    android:button="@null"/>

            <TypefaceRadioButton
                    android:id="@+id/button_filter_history"
                    android:text="@string/filter_history"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    style="@style/ButtonStyleRadio"
                    android:theme="@style/ButtonSecondary"
                    android:layout_alignParentRight="true"
                    android:button="@null"/>

        </RadioGroup>
        <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:nestedScrollingEnabled="false"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/radiogroup_filter"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:layout_marginBottom="50dp"/>
        <android.support.percent.PercentRelativeLayout
                android:id="@+id/container_links"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/recyclerview"
                android:visibility="gone">
            <ImageView
                    android:id="@+id/image_link_1"
                    app:layout_widthPercent="100%"
                    app:layout_aspectRatio="158%"
                    android:scaleType="centerCrop"
                    android:layout_alignParentTop="true"/>
            <TypefaceTextView
                    android:id="@+id/text_link_1"
                    android:text="@string/text_1"
                    app:layout_widthPercent="100%"
                    app:layout_aspectRatio="158%"
                    android:gravity="bottom|left"
                    android:paddingLeft="@dimen/activity_horizontal_margin"
                    android:paddingRight="@dimen/activity_horizontal_margin"
                    android:paddingTop="32dp"
                    android:paddingBottom="32dp"
                    style="@style/myStyle"
                    android:layout_alignParentTop="true"/>
            <ImageView
                    android:id="@+id/image_link_2"
                    app:layout_widthPercent="100%"
                    app:layout_aspectRatio="158%"
                    android:scaleType="centerCrop"
                    android:layout_below="@id/image_link_1"/>
            <TypefaceTextView
                    android:id="@+id/text_link_2"
                    android:text="@string/text_2"
                    app:layout_widthPercent="100%"
                    app:layout_aspectRatio="158%"
                    android:gravity="bottom|right"
                    android:paddingLeft="@dimen/activity_horizontal_margin"
                    android:paddingRight="@dimen/activity_horizontal_margin"
                    android:paddingTop="32dp"
                    android:paddingBottom="32dp"
                    android:layout_below="@id/image_link_1"
                    style="@style/myStyle"/>
        </android.support.percent.PercentRelativeLayout>
    </android.support.percent.PercentRelativeLayout>
</android.support.v4.widget.NestedScrollView>

最佳答案

我能够在我的测试项目中重现您的症状。我将其修复为在 Activity 的 onCreate() 中添加以下代码:

final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setOnFlingListener(new RecyclerView.OnFlingListener() {
    @Override
    public boolean onFling(int velocityX, int velocityY) {
        recyclerView.dispatchNestedFling(velocityX, velocityY, false);
        return false;
    }
});

我向 RecyclerView 添加了一个 fling 监听器,在 onFling() 中,我调用 dispatchNestedFling() 让父级知道正在发生一个 fling。然后 parent 可以消费这个 fling 或观察 child 的 fling。

https://developer.android.com/reference/android/support/v4/view/NestedScrollingChild.html#dispatchNestedFling(float, float, boolean)

dispatchNestedFling

added in version 22.1.0 boolean dispatchNestedFling (float velocityX, float velocityY, boolean consumed) Dispatch a fling to a nested scrolling parent.

This method should be used to indicate that a nested scrolling child has detected suitable conditions for a fling. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceeds the minimum fling velocity along a scrollable axis.

If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.

这在运行 API 19 的模拟器上运行。显然,YMMV。

关于android - API 19 ScrollView 没有动量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43287798/

有关android - API 19 ScrollView 没有动量的更多相关文章

  1. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  2. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

  3. ruby - 在没有 sass 引擎的情况下使用 sass 颜色函数 - 2

    我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re

  4. ruby-on-rails - ActionController::RoutingError: 未初始化常量 Api::V1::ApiController - 2

    我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc

  5. 没有类的 Ruby 方法? - 2

    大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow

  6. ruby-on-rails - Rails 3,嵌套资源,没有路由匹配 [PUT] - 2

    我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle

  7. ruby-on-rails - 有没有办法为 CarrierWave/Fog 设置上传进度指示器? - 2

    我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r

  8. ruby - 没有类方法获取 Ruby 类名 - 2

    如何在Ruby中获取BasicObject实例的类名?例如,假设我有这个:classMyObjectSystem我怎样才能使这段代码成功?编辑:我发现Object的实例方法class被定义为returnrb_class_real(CLASS_OF(obj));。有什么方法可以从Ruby中使用它? 最佳答案 我花了一些时间研究irb并想出了这个:classBasicObjectdefclassklass=class这将为任何从BasicObject继承的对象提供一个#class您可以调用的方法。编辑评论中要求的进一步解释:假设你有对象

  9. 【鸿蒙应用开发系列】- 获取系统设备信息以及版本API兼容调用方式 - 2

    在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList​()Obt

  10. ruby-on-rails - Mandrill API 模板 - 2

    我正在使用Mandrill的RubyAPIGem并使用以下简单的测试模板:testastic按照Heroku指南中的示例,我有以下Ruby代码:require'mandrill'm=Mandrill::API.newrendered=m.templates.render'test-template',[{:header=>'someheadertext',:main_section=>'Themaincontentblock',:footer=>'asdf'}]mail(:to=>"JaysonLane",:subject=>"TestEmail")do|format|format.h

随机推荐