2

我有一个NestedScrollView在CoordinatorLayout内,它包含一个recyclerView。整个片段很长,没有滚动的动力,我不知道我能做些什么来修复它。我以前有更高的Android版本的这个问题,并能够包括API 19滚动查看没有动能

android:nestedScrollingEnabled="false" 

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

下面是我的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> 

+0

你覆盖在你的应用程序中的onTouch或onDispatchTouch? –

+0

@LeandroBorgesFerreira我不是:/ – kjanderson2

+0

尝试更新您的评分文件和构建工具中的支持库 –

回答

4

我能够重新创建你的症状在我的测试项目。我固定它可以为活动添加在的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,并在onFling(),我称之为dispatchNestedFling(),让家长知道,一举一动正在发生。然后,父母可以消费投掷或观察孩子的投掷。

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

dispatchNestedFling在版本22.1.0 布尔dispatchNestedFling加入

(浮动velocityX, 浮子velocityY, 布尔消耗)派遣一个扫视到嵌套滚动父。

此方法应用于指示嵌套的滚动子 已检测到适合于一定范围的条件。一般来说,这意味着 触摸滚动已经以 滚动方向上的速度结束,该滚动满足或超过沿着可滚动轴的最小快速速度。

如果嵌套滚动子视图通常一扔,但它是在其自己的内容的 边缘,就可以用这个方法来扫视 委托给它的嵌套滚动父母代替。父母可以选择性地使用 消费投掷或观察孩子投掷。

这是工作在我的模拟器运行API 19.显然,YMMV。

+0

耶!它为我工作! – kjanderson2

+0

好!很高兴我能够帮助! –

+0

为我工作......谢天谢地! –

1

有一个简单的方法:

的Java

recyclerView.setNestedScrollingEnabled(false); 

科特林

recyclerView.isNestedScrollingEnabled = false 
+0

你读过这个问题了吗?我尝试过,但它不适用于API 19 ...接受的答案工作。 – kjanderson2

+0

@ kjanderson2老兄,它不是在使用XML,但它在onCreate中设置时有效。 –

+0

你是绝对正确的人!它的工作原理(y) –