标签: android-nestedscrollview

如何在底部检测滚动nestedscrollview android的位置?

我只是想在底部检测滚动nestedscrollview android的位置,以及调用函数.我的代码是:

scroll.getViewTreeObserver()
      .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
           @Override
           public void onScrollChanged() {
               int totalHeight = scroll.getChildAt(0).getHeight();
               int scrollY = scroll.getScrollY();
               Log.v("position", "totalHeight=" + totalHeight + "scrollY=" + scrollY);
               if (scrollY==totalHeight) {
                   getPlaylistFromServer("more");
               }
           }
      });
Run Code Online (Sandbox Code Playgroud)

但总高度与MAX ScrollY不同.怎么解决?

android android-nestedscrollview

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

NestedScrollView中的RecyclerView ScrollListener

我有一个EndlessRecyclerView结束了NestedScrollView.EndlessRecyclerView表示:当用户滚动到recyclerView的底部时,它会加载更多数据.这是已经实现的和其他地方的工作,但是当我把recyclerView内部NestedScrollViewOnScrollListener事件不火.

XML设计:

<NestedScrollView>

     <Other views/>

     <EndlessRecyclerView/>

</NestedScrollView >
Run Code Online (Sandbox Code Playgroud)

码:

recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            // This is never fired! Here is where I implement the logic of EndlessRecyclerView
        }
    });
Run Code Online (Sandbox Code Playgroud)

如何获得上述案例的滚动事件?

我知道在彼此内部有两个可滚动视图并不好.但是,如果没有两个可滚动的视图,我怎么能有上述情况呢?

我已经按照这个链接但它不起作用:scrollview android里面的recyclelerview滚动事件

android infinite-scroll onscrolllistener android-recyclerview android-nestedscrollview

22
推荐指数
1
解决办法
9325
查看次数

使用NestedScrollView,AppBarLayout和CoordinatorLayout平滑滚动和Fling

我正在开发一个应用程序,我正在使用带有CollapsingToolbarLayout和NestedScrollView的AppBarLayout.我已经成功实现了这个并且工作正常.

现在我想要做的是,在Nestedscrollview上进行快速刷卡时,它应该完全滚动到顶部.同样,在向屏幕底部投掷(快速向下滑动)时,它必须顺畅地滚动到底部.但是现在,它只会卡在两者之间,这使它看起来很难看.我已经尝试了许多可用的解决方案,但没有任何方法可以帮助我 我目前的设置如下.

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:zhy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="RtlHardcoded">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/main.collapsing"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/placeholder"
            android:layout_width="match_parent"
            android:layout_height="246dp"
            android:scaleType="fitXY"
            android:tint="#11000000"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.9" />


        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:padding="10dp">


            <FrameLayout
                android:id="@+id/back_frame"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:paddingBottom="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="10dp"
                android:paddingTop="5dp">

                <ImageView
                    android:id="@+id/back_image"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha" />
            </FrameLayout>


            <FrameLayout
                android:id="@+id/frameLayoutheart"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:layout_gravity="right|center_vertical"
                android:paddingBottom="5dp"
                android:paddingLeft="10dp"
                android:paddingRight="5dp"
                android:paddingTop="5dp">

                <ImageView
                    android:id="@+id/favbtnicon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/heart_profile" />
            </FrameLayout>


        </FrameLayout>

        <FrameLayout
            android:id="@+id/main.framelayout.title"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_gravity="bottom|center_horizontal"
            android:orientation="vertical"

            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.3">

            <LinearLayout …
Run Code Online (Sandbox Code Playgroud)

android android-collapsingtoolbarlayout android-appbarlayout android-nestedscrollview

17
推荐指数
2
解决办法
1万
查看次数

NestedScrollView无法使用match_parent height子进行滚动

我实现NonSwipeableViewPager与片段有这样的NestedScrollView,我期望的是scrollview可以向上滚动并显示2个textviews:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <include
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                layout="@layout/header" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="16dp"
                android:src="@drawable/ic_up" />

        </RelativeLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 2" />

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

但它无法滚动,我尝试了很多方法,但仍然没有得到任何解决方案

android android-nestedscrollview

16
推荐指数
3
解决办法
3万
查看次数

Android - 包含ExpandableListView的NestedScrollView在展开时不会滚动

我有一个ExpandableListView内部NestedScrollView(是的我知道,在另一个滚动视图中有一个滚动视图是不好的,但我不知道还有什么要做,请告诉我,如果有人知道更好的方法).

内容的大小NestedScrollView仍然在屏幕内,因此它不会滚动,但是当ExpandableListView展开时,内容将泄漏到屏幕外但NestedScrollView仍然不会滚动..为什么会这样?

这是我的NestedScrollView布局:

<NestedScrollView>
    <LinearLayout>
        <LinearLayout></LinearLayout>
        ... // About 3 of the LinearLayouts
        <ExpandableListView/>
    </LinearLayout>
</NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

android expandablelistview android-nestedscrollview

16
推荐指数
3
解决办法
8727
查看次数

16
推荐指数
2
解决办法
5814
查看次数

当层次结构中存在NestedScrollView时,Android不会调整我的布局大小

我刚刚在使用Android 7.1.1和Android支持库25.3.1的Nexus 9上观察到以下行为.

这是我的活动布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false"
        android:orientation="vertical"
        android:paddingBottom="4dp">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <View
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="#fffaaa" />

        <View
            android:id="@+id/view"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="#bbbaaa" />

        <View
            android:layout_width="match_parent"
            android:layout_height="10dp"
            android:background="#f00" />

    </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

这就是它在屏幕上的样子:

在此输入图像描述

当屏幕键盘显示时,系统调整活动的布局大小,从而占用从屏幕顶部到键盘的空间.请在下面的屏幕截图中考虑红色虚线:

在此输入图像描述

但是,当我ScrollView用a 替换时NestedScrollView,系统不会调整布局大小:

在此输入图像描述

现在红色虚线位于键盘下方.通过申请android:windowSoftInputMode="adjustResize"活动可以轻松解决该问题:

在此输入图像描述

红色虚线现在位于键盘上方.我的问题是:

  1. 为什么我会观察到这种行为?
  2. 怎么了NestedScrollView

android scrollview android-support-library android-nestedscrollview

15
推荐指数
1
解决办法
1031
查看次数

Recyclerview视图不能与setNestedScrollingEnabled一起使用,它也永远不会回收任何视图

我面临两个问题:

  1. 滚动侦听器将无法工作
  2. RecyclerView当它连接到一个从来不回收任何意见NestedScrollView.它就像ScrollView中的线性布局.它使用大量内存并造成滞后.

我在回收器视图的顶部附加了一个youtube播放器片段,因为我无法在回收器视图中放置片段.在我的代码中,您可以看到有一个框架布局.

我的布局看起来像这样:

    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nestedScroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <FrameLayout               
                android:layout_width="match_parent"
                android:layout_height="240dp"
                android:layout_alignParentTop="true"/>





        </LinearLayout>


        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/youtube_layout"
            android:visibility="visible"/>




    </LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

我想使用滚动侦听器来加载更多项目,所以我尝试了以下内容:

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    Log.i(TAG, "onScrolled: ");
    // bail out if scrolling upward or already loading data
    if (dy < 0 || dataLoading.isDataLoading()) return;

    final int visibleItemCount = recyclerView.getChildCount();
    final int totalItemCount = layoutManager.getItemCount(); …
Run Code Online (Sandbox Code Playgroud)

android onscrolllistener android-recyclerview android-nestedscrollview

14
推荐指数
1
解决办法
3169
查看次数

使用AppBarLayout.Behavior使用NestedScrollView顺利运行AppBarLayout

我有一个AppBarLayout和NestedScrollView.我想要NestedScrollView,只要它向下滚动,AppBarLayout也应该正常展开,而不会在AppBarLayout展开之前停止NestedScrollView; 完成第二次飞行/滚动需要完成.

我检查stackoverflow,发现这个解决方案非常相关,可以使用.但是如果是NestedScrollView,那就是RecyclerView.它位于/sf/answers/2271808521/

我基本上拿了代码并稍微改了一下,并用来检查速度> 8000以考虑将AppBarLayout作为下面的代码.

public final class FlingBehavior extends AppBarLayout.Behavior {
    private boolean isPositive;

    public FlingBehavior() {
    }

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

    @Override
    public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY, boolean consumed) {
        if (velocityY > 0 && !isPositive || velocityY < 0 && isPositive) {
            velocityY = velocityY * -1;
        }

        if (target instanceof NestedScrollView && Math.abs(velocityY) > 8000) {
            consumed = false;
        }
        return super.onNestedFling(coordinatorLayout, child, …
Run Code Online (Sandbox Code Playgroud)

android android-appbarlayout nestedscrollview android-nestedscrollview

13
推荐指数
1
解决办法
4689
查看次数

禁用 NestedScrollview 滚动

我的应用程序的设计

屏幕 - 1

    <NestedScrollview>
       <LinearLayout orientation:horizontal">
          <RecyclerView-1>
          <Framelayout>(contains Recyclerview-2)
    </NestedScroll>
Run Code Online (Sandbox Code Playgroud)

屏幕 - 2

     <NestedScrollview>
         <LinearLayout orientation:horizontal">
         <RecyclerView-1>
         <Framelayout> (fragment changed, contains Recyclerview-3)
     </NestedScroll>
Run Code Online (Sandbox Code Playgroud)

现在,如果用户在屏幕 1 上,则两个 recyclerview 将同时滚动,但在屏幕 2 上,如果用户滚动 RV1,则只有 RV1 会类似地滚动,如果 RV3 滚动,则 RV3 将滚动。尝试了各种停止滚动,但无法停止嵌套滚动视图的滚动。

android android-recyclerview android-framelayout android-nestedscrollview

13
推荐指数
2
解决办法
1万
查看次数