标签: android-nestedscrollview

NestedScrollView onBindViewHolder中的RecyclerView调用所有getItemCount大小

当我放入RecyclerView内部NestedScrollView然后onBindViewHolder调用所有行,比如说我有大小为30的列表然后一次onBindViewHolder调用所有30行,即使没有滚动

 RecyclerView list;
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        list.setLayoutManager(layoutManager);
        layoutManager.setAutoMeasureEnabled(true);
        list.setNestedScrollingEnabled(false);
        list.addItemDecoration(new VerticalSpaceItemDecoration(5));
        list.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

我的xml是

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="none"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/grey">
    <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_views"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/info"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:textAlignment="center"

            android:visibility="visible"
           />
Run Code Online (Sandbox Code Playgroud)

但如果我删除NestedScrollView它正常工作.

android android-recyclerview nestedscrollview android-nestedscrollview

9
推荐指数
1
解决办法
1394
查看次数

在NestedScrollView中使用RecyclerView的ItemTouchHelper:拖动滚动不起作用

我已经实现了如下所述的ItemTouchHelper:https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-b9456d2b1aaf#.k7xm7amxi

如果RecyclerView是CoordinatorLayout的子项,则一切正常.

但是如果RecyclerView是CoordinatorLayout中NestedScrollView的子代,则拖动滚动不再起作用.拖动项目并将其移动到屏幕的顶部或底部,RecyclerView不会像它不是NestedScrollView的子项那样滚动.

有任何想法吗?

android android-recyclerview android-nestedscrollview itemtouchhelper

9
推荐指数
1
解决办法
860
查看次数

SwipeRefreshLayout不拦截NestedScrollingChild的MotionEvent

我使用的是NestedScrollWebView(在很大程度上受到影响NestedScrollView),这可以解决许多已知 问题与使用相关联WebViewCoordinatorLayout.

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

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

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="enterAlways|scroll|snap">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:titleTextAppearance="@style/TextAppearance.AppCompat.Subhead"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

            <ProgressBar
                android:id="@+id/progressBar"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_gravity="bottom"
                android:visibility="gone"
                style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>

        </FrameLayout>

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <com.example.app.widget.NestedScrollWebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </android.support.v4.widget.SwipeRefreshLayout>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这些NestedScrollWebView作品很好用AppBarLayoutenterAlways|scroll|snap滚动标志,但不是很好SwipeRefreshLayout.


我删除了以下行NestedScrollWebView:

setOverScrollMode(WebView.OVER_SCROLL_NEVER);
Run Code Online (Sandbox Code Playgroud)

这样可以确保视图不会显示在滚动指示器上.我想要显示滚动指示符,但即使启用了过度滚动,也不会出现以下情况.


根据我的理解,SwipeRefreshLayout应该拦截导致刷新指示符被拖动的任何触摸事件(基于其实现onInterceptTouchEvent()).SwipeRefreshLayout也拒绝任何requestDisallowInterceptTouchEvent()已启用嵌套滚动的子项; 这是真的NestedScrollWebView.因此,应按 …

android swiperefreshlayout android-touch-event android-nestedscrollview

9
推荐指数
1
解决办法
544
查看次数

在 NestedScrollView 中使用 PagedListAdapter

我有一个RecyclerViewPagedListAdapter.

当我把RecyclerView里面NestedScrollViewPagedList不能计算列表的末尾所以开始请求新数据的连续突发。

主要问题是我应该如何使用PagedListAdapterinside NestedScrollView

android-nestedscrollview android-paging

9
推荐指数
1
解决办法
693
查看次数

如果 RecyclerView 在 NestedScrollView 中,则 findLastVisibleItemPosition 返回错误的值

我在 NestedScrollView 中有 RecyclerView

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

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

我在大项目中遇到了这个问题,为了找到这个问题的解决方案,我创建了没有其他视图的新项目。

这是 MainActivity 的完整代码

class MainActivity : AppCompatActivity() {

    var mItems = mutableListOf<String>()
    var mAdapter = MyAdapter(mItems)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        recycler.layoutManager = LinearLayoutManager(this)
        recycler.adapter = mAdapter

        delayedLoadDataIfPossible(100)

        recycler.viewTreeObserver.addOnScrollChangedListener {
            delayedLoadDataIfPossible(100)
        }

    }

    private fun delayedLoadDataIfPossible(delay: Long) {
        Observable.timer(delay, TimeUnit.MILLISECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    var scrollingReachedEnd = isScrollingReachedEnd()
                    if (scrollingReachedEnd) {
                        loadData()
                    }
                }
    }

    private fun isScrollingReachedEnd(): Boolean {
        val layoutManager = LinearLayoutManager::class.java.cast(recycler.layoutManager)
        val …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-nestedscrollview

9
推荐指数
2
解决办法
2478
查看次数

Android Nested Scrollview不滚动

我有一个嵌套ScrollView,其中包含线性布局内的内容.

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:CoverFlowPager="http://schemas.android.com/apk/res-auto"
    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.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:clipToPadding="false"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

    </android.support.v4.widget.NestedScrollView>

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

我在ViewPager中有这个布局,ViewPager在CordinatorLayout里面.

<android.support.design.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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
Run Code Online (Sandbox Code Playgroud)

现在,当我滚动视图时,视图不会滚动.但由于布局位于Cordinator布局内,因此向上移动直到ToolBar被隐藏.但它没有向上滚动.

这是我的主要活动xml,视图寻呼机位于选项卡式布局中.

<android.support.design.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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

           <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                xmlns:attrs="http://schemas.android.com/apk/res-auto"
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/AppTheme.PopupOverlay">

            <FrameLayout
                android:id="@+id/titleContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"    
                android:gravity="center">

                <com.CustomFontTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Toolbar Title"
                    android:textColor="#ffffff"
                    attrs:customFont="handyman_bold"
                    android:textSize="8pt"
                    android:layout_marginLeft="-20dp"
                    android:id="@+id/toolbar_title"/>
            </FrameLayout>

            <ImageButton
                android:id="@+id/btn_ToolBarRightBtn"
                android:layout_width="32dp"
                android:layout_height="28dp"
                android:tag="0" …
Run Code Online (Sandbox Code Playgroud)

android android-nestedscrollview

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

将Android NestedScrollView水平滑动传递给父视图

我正在尝试制作一个左右可刷卡系统(如Tinder),卡上有一个NestedScrollView.目标是如果用户仅向上和向下滑动,NestedScrollView将滚动,但如果用户向左或向右滑动,则卡将使用该滑动.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="4dp"
    card_view:cardUseCompatPadding="true">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nested_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <TextView
                android:id="@+id/text_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

(我使用的卡库是https://github.com/wenchaojiang/AndroidSwipeableCardStack)

compile 'com.github.wenchaojiang:AndroidSwipeableCardStack:0.1.5'
Run Code Online (Sandbox Code Playgroud)

当我在NestedScrollView上放置margin_top并在该边距内触摸时,CardStack正确地抓取我的输入并且卡片向左或向右移动,但是如果我触摸并拖动其他任何地方,NestedScrollView会抓住我的输入而不管方向.

我应该扩展/覆盖哪个类/ onTouchEvent以产生这种效果,或者可能有更简单的方法?

谢谢!

android android-custom-view ontouchlistener touch-event android-nestedscrollview

8
推荐指数
1
解决办法
892
查看次数

NestedScrollView setOnScrollChangeListener api 21

大家好,我正在尝试处理onScrolledrecyclerViewNestedScrollView.

到目前为止,我已经发现setOnScrollChangeListener,但是这个方法是 API 23,我的目标是 API 21,有什么想法可以在 API 21 中处理这个问题吗?

android onscrolllistener android-recyclerview android-nestedscrollview

8
推荐指数
2
解决办法
7766
查看次数

带有 RecyclerView 滚动问题的垂直 ViewPager2

我正在使用带有两个垂直方向的片段的 ViewPager2。当用户向下滑动到第二个片段时,有一个 RecyclerView 在同一垂直方向滚动内容。

问题是当我滚动 RecyclerView 的内容时,有时 ViewPager2 捕获滚动事件,有时 RecyclerView 捕获滚动事件。

我希望这样,当用户滚动到 RecyclerView 的顶部时,ViewPager 仅在用户到达 RecyclerView 内容的顶部时才滑回第一个片段。

我试过使用 recyclerView.isNestedScrollingEnabled = false,但运气不佳。我也尝试将 RecyclerView 放入 NestedScrollView,但不推荐这样做,因为 RecyclerView 然后创建它需要的数据集的每个 ViewHolder,这显然效率不高。

vertical-scrolling android-fragments android-recyclerview android-nestedscrollview android-viewpager2

8
推荐指数
2
解决办法
7955
查看次数

当与 viewpager 和 recyclerview 一起使用时,CollapsingToolbarLayout 的部分内容变得粘在上面

我正在尝试实现这样的布局:

在此处输入图片说明

问题是,当向上滚动卡片时,它会接触到工具栏,并且不再像这样向上滚动:

在此处输入图片说明

我希望它向上滚动直到 viewpager 填满屏幕,即至少矩形卡应该向上滚动到工具栏之外(即使 tabLayout 也可以向上滚动)。但我不希望它在顶部保持粘性。

主要布局在这里:

 <?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"
    tools:showIn="@layout/activity_main">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/background_dark"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="190dp"
                android:minHeight="190dp"
                android:src="@drawable/ic_launcher_foreground"
                app:layout_collapseMode="parallax" />


            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_collapseMode="pin" />

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


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


    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:behavior_overlapTop="90dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <include layout="@layout/debit_card_item" />


            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:layout_marginTop="40dp"
                android:background="?attr/colorPrimary" />


            <androidx.viewpager.widget.ViewPager
                android:id="@+id/viewPager"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />

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

寻呼机的片段位于 NestedScrollView 中,如下所示:

<?xml …
Run Code Online (Sandbox Code Playgroud)

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

8
推荐指数
1
解决办法
888
查看次数