相关疑难解决方法(0)

在NestedScrollView中使用RecyclerView时,它不会回收视图

我在RecyclerView里面用NestedScrollView.我也设置setNestedScrollingEnabled为假recyclerview

支持较低的API

ViewCompat.setNestedScrollingEnabled(mRecyclerView, false);

现在!当用户滚动视图时,每件事似乎都没问题,但是!!! recyclerview中的视图不回收!和堆大小迅速增长!!

更新:RecyclerView布局管理器是StaggeredLayoutManager

fragment_profile.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/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

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

                <!-- RecyclerView and NestedScrollView -->
                <include layout="@layout/fragment_profile_details" />

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

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

fragment_profile_details.xml:

<LinearLayout
    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/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:orientation="vertical" >

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nested_scrollbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="fill_vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:fillViewport="true"
            android:scrollbars="none" >

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

                        <android.support.v7.widget.CardView
                            android:id="@+id/profileCardview"
                            android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android recycle android-recyclerview nestedscrollview

55
推荐指数
1
解决办法
8783
查看次数

如何在ListView上获得滚动速度?

我有一个带有onScrollStateChanged和onScroll事件监听器的ListView.我希望能够得到ListView控件或某种方式来获得一些事件侦听器的启动滚动的finalX位置的滚动速度.我们的应用程序针对SDK版本7.

我需要测量或获得ListView滚动的速度.

java android

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

如何使RecyclerView在NestedScrollView中进行回收?

我试图将包括在内的几种观点RecyclerView纳入NestedScrollView。我曾经用过setNestedScrollingEnabled(false),它对于小型数据集看起来不错,但对于大型数据集却开始变得迟钝。

在花了一些时间记录该onCreateViewHolder()方法之后,我了解到回收者视图会像旧的一样立即创建它们ListView。我试图在RecyclerView文档中找到这种行为的原因,但是我在ScrollView description中找到了:

永远不要将ScrollView与ListView一起使用,因为ListView负责其自身的垂直滚动。最重要的是,这样做会挫败ListView中处理大型列表的所有重要优化,因为它有效地迫使ListView显示其整个项目列表,以填充ScrollView提供的无限容器。

我希望这NestedScrollView可以解决问题,但事实并非如此。

是否有任何方法,例如,使用一些自定义项LayoutManagerRecyclerView优化视图回收?

Ps当然,我知道getItemViewType(int pos)使用这种技术添加自定义页眉和页脚的方法和可能性,但是对我来说这似乎是一个丑陋的解决方法。是的,我目前正在使用它,因为拥有比这样大的性能问题更难维护的代码更好。

optimization android recycle android-scrollview android-recyclerview

6
推荐指数
0
解决办法
2020
查看次数

如何在垂直recyclerview android中实现Vertical Recyclerview?

假设我有2 个项目,其中RecyclerView每个项目innerrecyclerview有大约100 个项目,它们都是垂直的或任何对现有问题没有任何影响的项目。

我已经在其他 stackoverflow 问题或其他 android 博客上实现了此处提供的方法,但没有帮助。

我有一个问题onbindviewholder,项目 1 内部RecyclerViewonbindviewholder所有元素(即 100 个)一次被调用,并且它们没有回收或任何东西,因为onbindviewholder没有通过滚动来调用,而这应该是正常行为RecyclerView

以及如何进行innerrecyclerview回收,因为所有其他帖子都没有谈到这一点。

CourseRVAdapter 或 ParentAdapter

public class CourseRVAdapter extends RecyclerView.Adapter<CourseRVAdapter.SimpleViewHolder> {

        private Context mContext;
        private List<data> merchantlist;
        private List<data> merchantlist2;
        private RecyclerView horizontalList;
        Typeface MRR;
        private Typeface MR;


        public class SimpleViewHolder extends RecyclerView.ViewHolder {
            public final TextView title;
            private HorizontalRVAdapter horizontalAdapter;

            public SimpleViewHolder(View view) {
                super(view); …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

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

ViewPager2 里面有水平滚动视图

我为我的项目实现了新的 ViewPager。viewPager2 包含一个片段列表

 private class ViewPagerAdapter extends FragmentStateAdapter {

    private ArrayList<Integer> classifiedIds;

    ViewPagerAdapter(@NonNull Fragment fragment, final ArrayList<Integer> classifiedIds) {
        super(fragment);
        this.classifiedIds = classifiedIds;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return DetailsFragment.newInstance(classifiedIds.get(position));
    }

    @Override
    public int getItemCount() {
        return classifiedIds.size();
    }
}
Run Code Online (Sandbox Code Playgroud)

在片段内部我得到了一个水平的 recyclerView

LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerViewPicture.setLayoutManager(layoutManager);
Run Code Online (Sandbox Code Playgroud)

问题是当我尝试滚动 recyclerview 时,viewPager 触摸并切换到下一个片段

当我使用旧的 ViewPager 时,我没有这个问题

android android-recyclerview android-touch-event android-viewpager2

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