gpt4 book ai didi

android - API 19 ScrollView 没有动量

转载 作者:数据小太阳 更新时间:2023-10-29 02:47:39 25 4
gpt4 key购买 nike

我在 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.0boolean 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 childhas detected suitable conditions for a fling. Generally this meansthat a touch scroll has ended with a velocity in the direction ofscrolling that meets or exceeds the minimum fling velocity along ascrollable axis.

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

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

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

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