标签: android-nestedscrollview

NestedScrollView.OnScrollChangedListener 不起作用

我正在编写一个具有 NestedScrollView 的应用程序。我想处理滚动是否发生变化。我在互联网上搜索,发现我必须创建自定义 ScrollView。这是我的代码:

public interface OnScrollChangedListener {

    void onScrollChanged(MyScrollView nestedScrollView, int l, int t, int oldl, int oldt);

}
Run Code Online (Sandbox Code Playgroud)

首先,我创建了一个界面来处理滚动更改,然后我创建了自定义 NestedScrollView

public class MyScrollView extends NestedScrollView{

    private OnScrollChangedListener onScrollChangedListener;

    public void setOnScrollChangedListener(OnScrollChangedListener onScrollChangedListener) {
        this.onScrollChangedListener = onScrollChangedListener;
    }

    public MyScrollView(Context context) {
        super(context);
    }

    public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, …
Run Code Online (Sandbox Code Playgroud)

android onscrollchanged android-nestedscrollview

5
推荐指数
0
解决办法
860
查看次数

具有多个捕捉点的 CoordinatorLayout

这里我有一个相当复杂的动画,可以使用 CoordinatorLayout 以简单的方式解决(我相信。它有3个状态:

\n\n
    \n
  1. 初始(左屏幕)- 标题视图完全显示(橙色\n背景):工具栏、灰色圆形矩形(实际上是一张照片)\n以及下面的一些其他视图(TextViews、RatingBar等)
  2. \n
  3. 向上滚动内容(屏幕中间\n) - 圆矩形正在放大,其上的绿色前景 alpha 级别不断变化,因此滚动时它会变成绿色(嗯,在这些屏幕上并不明显。绿色背景实际上是一个缩放的圆矩形,其上有绿色前景,这就是标题背景变为绿色而不是橙色的原因)
  4. \n
  5. 再次滚动(右屏幕)-标题的其余部分应该向上滚动
  6. \n
\n\n

向下滚动内容应该会相应地导致视图以相反的方式出现。

\n\n

CoordinatorLayout 状态

\n\n

我有一些使用 CoordinatorLayout 的经验,但我真的不确定我是否理解如何处理 2 个锚点。我了解滚动标志的工作原理以及缩放(第 2 页)和更改前景 alpha 的工作原理,我需要一个自定义行为实现,但现在我无法理解如何在复杂的情况下处理所有这些。

\n\n

到目前为止我找到的只是Sa\xc3\xbal Molinero\ 的教程以及带有示例的教程

\n\n

因此,请为这里的糟糕描述感到抱歉,我当然会更新我的问题,并在我在这个问题上取得一些成功时添加源代码,但现在我很高兴得到一些提示或教程我\已经错过了。希望有人在项目中有类似的东西。

\n\n

这是我的测试存储库及其代码,这是我的layout.xml文件的链接。

\n

android android-animation android-coordinatorlayout android-collapsingtoolbarlayout android-nestedscrollview

5
推荐指数
1
解决办法
2643
查看次数

NestedScroll视图检测滚动状态

我试图在 STATE_IDLE 或 DRAGGING 时检测滚动状态。作为参考,我找到了这个答案:

/sf/answers/2636738051/

这帮助我了解了基本的想法,我实现了它,但它只是检测 STATE_IDLE 和强制方法

@Override
public void stopNestedScroll() {
    super.stopNestedScroll();
    dispatchScrollState(RecyclerView.SCROLL_STATE_IDLE);
}
Run Code Online (Sandbox Code Playgroud)

另外两个方法 onStartNestedScroll 和 startNestedScroll 永远不会被调用,所以由于检查dispatchScrollState中的状态,我永远不会在扩展接口的地方调用我的方法。

我添加的唯一额外的事情是我扩展了我的课程

NestedScrollingView.NestedScrollViewScrollStateListener 
Run Code Online (Sandbox Code Playgroud)

并将此类中的scrollListener设置为:

nestedScrollView.setScrollListener(this);
Run Code Online (Sandbox Code Playgroud)

那么是什么原因导致它不调用启动方法呢?

android android-nestedscrollview

5
推荐指数
0
解决办法
1058
查看次数

具有约束布局的 NestedScrollView 不滚动

我的 xml 由一个约束布局组成。其中有 2 个按钮和 1 个嵌套滚动视图。里面ScrollView有各种元素,包括回收视图。我希望回收视图不滚动,而只滚动嵌套的滚动视图。我在此模式 ( recyclerView.setNestedScrollingEnabled(false);) 中禁用了回收视图的滚动,但问题是嵌套滚动视图不滚动。你能帮助我吗?我附上下面的代码。

代码以这种模式开始:

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
    android:id="@+id/azzera"
    android:layout_width="120dp"
    android:layout_height="40dp"
    android:layout_marginStart="40dp"
    android:layout_marginBottom="28dp"
    android:background="@drawable/rounded_4lati"
    android:backgroundTint="@color/azzurro"
    android:elevation="@dimen/dimen8"
    android:paddingTop="@dimen/dimen8"
    android:text="@string/azzera"
    android:textAlignment="center"
    android:textColor="#FFFFFF"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<TextView
    android:id="@+id/conferma"
    android:layout_width="120dp"
    android:layout_height="40dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="28dp"
    android:background="@drawable/rounded_4lati"
    android:backgroundTint="@color/azzurro"
    android:paddingTop="@dimen/dimen8"
    android:text="@string/conferma"
    android:textAlignment="center"
    android:textColor="#FFFFFF"
    android:elevation="@dimen/dimen8"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent" />

<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:fillViewport="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    >

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/view1"
            android:layout_width="0dp"
            android:layout_height="48dp"
            android:background="@color/white"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <View
            android:id="@+id/view2" …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-nestedscrollview android-constraintlayout

5
推荐指数
2
解决办法
3907
查看次数

NestedScrollView + CodinatorLayout scrollBy() scrollTo() 方法什么都不做

我有一个 NestedScrollView 与 CoordinatorLayout + AppBarLayout + CollapsingToolbarLayout 一起使用,具有类似于本教程的视差效果

我需要以编程方式滚动内容(最好是平滑滚动,即动画),但是调用滚动方法(scrollBy()、scrollTo()、smoothScrollTo()、smoothScrollBy())什么也不做。

请注意,我正在使用app:layout_behavior="@string/appbar_scrolling_view_behavior"<-- 不确定问题是否与此有关。

nsv_form.smoothScrollBy(0, 300)当用户单击按钮时,我正在调用Kotlin,但没有任何反应:(

(也尝试过scrollTo(),,scrollBy()+- 300,各种不同的变化)

更新:我研究了源代码,似乎这些*scroll*()方法期望布局的内容大于父视图(有道理)。就我而言,内容较小,所以我怀疑这就是滚动方法不起作用的原因。也许我需要不同的东西而不是scroll?

NestedScrollView 的位置开始部分离开屏幕,上面有一个 CollapsingToolbarLayout 中的图像,就像这样,所以看起来我需要以编程方式移动 NestedScrollView 的位置并触发 CoordinatorLayout 的滚动行为。 - 我该怎么做呢?

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/iv_image"
                android:layout_width="match_parent"
                android:layout_height="@dimen/image_height"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                tools:src="@drawable/some_image" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:id="@+id/nsv_form"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout …
Run Code Online (Sandbox Code Playgroud)

android android-coordinatorlayout android-nestedscrollview

5
推荐指数
1
解决办法
1095
查看次数

由于滑动刷新布局,我无法向上滚动

有很多类似的问题,但我的有点不同。向下滚动时,该活动完美运行。但是,当我向上滚动时,它会刷新,而不是滚动。我真正想要的是,只有当我位于嵌套滚动视图的顶部时,它才会刷新。我必须快速双击才能向上滚动,这有点困难。

截屏:

在此输入图像描述

详细信息.xml

     <?xml version="1.0" encoding="utf-8"?>
  <android.support.v4.widget.SwipeRefreshLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".details">
 <android.support.design.circularreveal.
 coordinatorlayout.CircularRevealCoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true"
    >

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="#0e0d0e"
        app:expandedTitleTextAppearance="@android:color/transparent"
        >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/img_beach"
            android:contentDescription="@null"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:title="Beach Name"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="parallax"
            />
    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


<android.support.design.widget.FloatingActionButton
    android:id="@+id/btnSubmit"
    android:src="@drawable/send"
    android:backgroundTint="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:elevation="6dp"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|end"
    app:pressedTranslationZ="12dp"
    app:useCompatPadding="true"
    />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/btn_rating"
    android:src="@drawable/ic_add_black_24dp"
    android:backgroundTint="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:elevation="6dp"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|start"
    app:pressedTranslationZ="12dp"
    app:useCompatPadding="true"
    />

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android swiperefreshlayout android-nestedscrollview

5
推荐指数
3
解决办法
6340
查看次数

CollapsingToolbarLayout 不与 RecyclerView 滚动行为折叠

我有一个显示图像的 CollapsingToolbarLayout(放置在 ConstraintLayout 内以保持比例为 1:1)和一个com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior附加到它的 RecyclerView 。

布局图

图像为绿色,RecyclerView 为蓝色。

问题是当我在 RecyclerView 上向上滚动时,CollapsingToolbarLayout 不会折叠。相反, RecyclerView 只是在整个布局下方滚动。我必须在 CollapsingToolbarLayout 内手动滚动才能折叠。

这是布局的代码:

<androidx.coordinatorlayout.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:src="@drawable/ic_launcher_background"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintDimensionRatio="1:1"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorPrimary"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent"
        android:nestedScrollingEnabled="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar" …
Run Code Online (Sandbox Code Playgroud)

scroll android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout android-nestedscrollview

5
推荐指数
1
解决办法
445
查看次数

当nestedscrollview 中的recyclerview 滚动时,对讲焦点转到工具栏项

我的布局中有一个nestedscrollview,其中包含很少的文本、按钮和recyclerviews。

当对讲打开时,我可以遍历所有元素。但我面临一个问题。当我的水平 recyclerview 滚动然后我滑动以听到对讲时,焦点将移动到工具栏的第一项。然后我需要遍历所有可见项以到达水平滚动视图滚动项。

这个问题只出现在nestedscrollview 中的recyclerviews 中。

我在布局中的嵌套滚动视图以这种方式添加:

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        //my contents

</androidx.core.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

我在布局中的 recyclerview 以这种方式添加:

<LinearLayout
     android:id="@+id/photosLL"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical">

     <androidx.recyclerview.widget.RecyclerView
          android:id="@+id/photosRV"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          tools:listitem="@layout/list_item_photo" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是预期的行为还是问题,如何解决?

android talkback android-recyclerview android-accessibility android-nestedscrollview

5
推荐指数
1
解决办法
698
查看次数

一个视图中的多个回收器视图(网格布局和水平线性布局)

我正在努力实现这一目标:

(

首先,我尝试将我所有的回收视图(带有 WRAP_CONTENT)放在一个nestedscrollview 中。那行得通,但表现很糟糕。然后我尝试为我的 recyclerviews 设置一个高度,这好多了(尤其是第一个 gridlayout 和水平线性布局加载非常快),但仍然存在动态“类别”部分的问题。

现在我试图将我所有的回收站视图放在一个具有不同视图类型的回收站视图中。由于这是一个很大的问题(我需要重构很多代码,因为我已经将屏幕截图中的每个区域都放在了一个片段中,现在我需要将所有这些代码放在一个适配器中)我想问一下我是否真的可以期望从中获得任何收益,因为最终它又是一个“嵌套滚动视图”(由我自己制作,但是......)。或者,如果有其他一些“最佳实践”方式来实现这种布局。

谢谢

编辑:正如预期的那样,这也没有起到作用。当仅将两个第一个 recyclerviews 添加为 viewtype 时,它​​会平滑地滚动和加载。但是,一旦我尝试添加类别项(在类别下方),我就会注意到延迟,尤其是在选择多个类别并快速向上滚动时,会出现明显的延迟。我想我将不得不改变我的布局并将类别选择部分移动到一个单独的视图中,只需要提出一个用户友好的解决方案。但实际上非常令人失望的是,在我看来,布置多个表这样微不足道的任务在 android 上是一件很痛苦的事情。

performance layout android android-recyclerview android-nestedscrollview

5
推荐指数
1
解决办法
423
查看次数

将 ConstraintLayout 放置在 NestedScrollView 中时如何使用整个空间?

我试图将 a 放入ConstraintLayouta 内NestedScrollView,但有一条线将ConstraintLayout. 我不能在那条看不见的线下面放置任何东西。我已经尝试了几个小时,但找不到问题所在。

在此输入图像描述

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <androidx.core.widget.NestedScrollView
        android:id="@+id/premium_layout_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#BFFFFFFF"
        android:focusableInTouchMode="true"
        android:tag="layout/fragment_premium"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            tools:context=".PremiumFragment">

            <ImageView
                android:id="@+id/launcher_id"
                android:layout_width="185dp"
                android:layout_height="185dp"
                android:layout_marginTop="25dp"
                android:layout_marginBottom="20dp"
                android:contentDescription="TODO"
                app:layout_constraintBottom_toTopOf="@+id/premium_text_id"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/launch_premium" />

            <TextView
                android:id="@+id/premium_text_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="220dp"
                android:text="@string/launch_to_premium"
                android:textSize="24sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView2"
                android:layout_width="383dp"
                android:layout_height="196dp"
                android:layout_marginTop="24dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/premium_text_id" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>
</layout>
Run Code Online (Sandbox Code Playgroud)

android android-nestedscrollview

5
推荐指数
1
解决办法
132
查看次数