kja*_*on2 2 xml layout android android-4.4-kitkat android-coordinatorlayout
我在CoordinatorLayout中有一个NestedScrollView,它包含一个recyclerView.整个片段很长,没有滚动动量,我不知道我能做些什么来修复它.我以前有更高的Android版本的问题,并能够包括
android:nestedScrollingEnabled="false"
Run Code Online (Sandbox Code Playgroud)
解决我的问题.但是,这是在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>
Run Code Online (Sandbox Code Playgroud)
我能够在我的测试项目中重现你的症状.我修复了它在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;
}
});
Run Code Online (Sandbox Code Playgroud)
我在RecyclerView中添加了一个狡猾的监听器,在onFling()中,我调用了dispatchNestedFling()让父进程知道正在发生抛出.然后,父母可以消费掉或观察孩子的摔跤.
dispatchNestedFling
在版本22.1.0中添加boolean dispatchNestedFling(float velocityX,float velocityY,boolean consume)将一个fling发送到嵌套的滚动父级.
此方法应用于指示嵌套滚动子项已检测到适合的条件.通常,这意味着触摸滚动已经以滚动方向上的速度结束,该速度满足或超过沿着可滚动轴的最小甩动速度.
如果嵌套的滚动子视图通常会抛出但它位于其自己内容的边缘,则可以使用此方法将fling委托给其嵌套的滚动父级.父母可以选择消费甩尾或观察儿童甩尾.
这是在我运行API 19的模拟器上运行.显然,YMMV.
有一个更简单的方法:
爪哇
recyclerView.setNestedScrollingEnabled(false);
Run Code Online (Sandbox Code Playgroud)
科特林
recyclerView.isNestedScrollingEnabled = false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1924 次 |
| 最近记录: |