标签: linearlayoutmanager

Android - NestedScrollView内的RecyclerView上的性能问题

我有一个NestedScrollViewRecyclerView和一个RelativeLayout位于内..

基本上就是这样

<NestedScrollView>

<RelativeLayout> //To contain the stuffs inside

    <RelativeLayout /> // Contains a `TextView` and a `ProgressBar`

    <RecyclerView /> // The most important thing.. Maybe

</RelativeLayout>

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

我正在使用一个CustomLinearLayoutManager并且recyclerView.setNestedScrollingEnabled(false);为了滚动两个RelativeLayoutRecyclerView一起,否则,只有RecyclerView会滚动,RelativeLayout它将保持在它的顶部.

每当RecyclerView加载新数据时,它会冻结3-5秒,这对用户体验非常不利..这就是CustomLayoutManager我正在使用的..

public class CustomLayoutManager extends LinearLayoutManager {

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

    public CustomLayoutManager(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
    }

    public CustomLayoutManager(Context context, AttributeSet …
Run Code Online (Sandbox Code Playgroud)

android linearlayoutmanager

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

具有LinearLayoutManager和预测动画的RecyclerView

我正在使用垂直的LinearLayout Manager和DefaultItemAnimator构建相对简单的RecyclerView。它只会处理添加和删除项目(无动画更改,交换,移动等)

我的项目将被添加到列表中的特定位置,因为它以特定顺序排序,因此列表必须滚动到添加项目的位置才能向用户显示。

还有一个棘手的部分-LinearLayoutManager和DefaultItemAnimator似乎并未构建为支持预测动画。当前,由于滚动,所有出现的项目都被动画化,而不仅仅是新添加的项目,并且我只想在新项目上运行特定的动画。

首先,我在这里阅读了文档,其中说:

想要获得更好的项目动画体验的LayoutManager,可以根据项目不在屏幕上时存在的位置对项目进行动画显示,然后在LayoutManager上从supportsPredictiveItemAnimations()返回true,并向onLayoutChildren(州回收商)

这是的文档RecyclerView.LayoutManager,因此LinearLayoutManager孩子应该已经具有该附加逻辑(或没有?)

问题在于它的onLayoutChildren方法太复杂了,我不确定为了将“出现在屏幕上”和“全新”视图区分开来,应该准确修改哪个部分。

我还阅读了本教程该教程可以解决我的确切问题,但是该示例使用了FixedGridLayoutManager,但再次发现,它太复杂了,无法理解和调整整个布局逻辑。

我不是在寻找现成的复制粘贴解决方案,但是我需要一些有关了解布局功能的线索。恐怕编写自己的代码,除了乏味之外,还必然会产生更糟糕的结果,因为其中已经有200行代码是由比我聪明的人编写的^^

理想情况下,我想在其中添加一些内容或进行一些小的更改,以免破坏整体的度量,报废,回收利用以及其中发生的任何其他复杂内容。

在此先感谢,欢迎您的帮助

animation android android-recyclerview linearlayoutmanager

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

RecyclerView:设置滚动位置,使项目显示在视图的底部

我有RecyclerView一个LinearLayoutManager由与项目适配器支持不同高度的.有没有办法告诉RecyclerView设置滚动位置,以便项目X(或多或少)出现在屏幕的底部?

我试过LinearLayoutManager.scrollToPosition()但这会将项目放在视图的顶部.

android android-recyclerview linearlayoutmanager

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

带有SnapHelper的RecyclerView上的有害反弹效果

我正在将RecyclerView与Horizo​​ntal LinearLayoutManager一起使用。

recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false));

为了将适配器项卡在中间,我将LinearSnapHelper附加到了recyclerview。

SnapHelper helper =新的LinearSnapHelper();

helper.attachToRecyclerView(recyclerView);

现在,我有两种情况希望将物品放到中心

  1. 当我的活动启动时,它应该以特定项目为中心启动。
  2. 在recyclerview中点击某个项目时,它应该居中。为此,我重写了适配器的ViewHolder中的OnClick方法。

对于这两种情况,我正在使用

recyclerView.smoothScrollToPosition(position);

物品就居中了。但是,这发生在有弹性的动画中,其中首先会发生一些额外的滚动,然后将其弹回。

如何禁用此弹性动画以平滑滚动?

我尝试过的事情-在下面的API中代替了smoothScrollToPosition

  1. LinearLayoutManager.scrollToPosition()
  2. LinearLayoutManager.scrollToPositionWithOffset()

上面的两个API都无法流畅滚动,而且项目无法正确居中(因为很难找出在API调用期间尚未创建/回收的项目的正确偏移值)

我在RecyclerView的文档中找不到任何禁用/覆盖动画的方法。有人可以帮忙吗..

android android-recyclerview linearlayoutmanager

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

Android LinearSnapHelper - 如何提高滚动/"捕捉"速度?

我正在使用LinearSnapHelper将我的RecyclerView中的项目"捕捉"到屏幕上"卡住"(我的卡占据了大部分屏幕,因此我希望它们能够卡入到位并在每次滑动/滚动/滚动时填充屏幕) .

我正在努力解决如何让卡片更快地卡入到位的问题.我已经尝试创建自定义LinearLayoutManager(并在scrollToPosition或smoothScrollToPosition中编辑calculateSpeedPerPixel方法),以及自定义RecyclerView(并编辑fling方法).但没有什么能影响卡片"卡入"的速度.

我想问题是我并不真正理解LinearSnapHelper如何将卡片"滚动"到位.它似乎没有使用LinearLayoutManager的scrollToPosition或smoothScrollToPosition方法.

有帮助吗?非常感谢!

    snapHelper = new LinearSnapHelper() {
        @Override
        public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
            View centerView = findSnapView(layoutManager);
            if (centerView == null) {
                return RecyclerView.NO_POSITION;
            }

            int position = layoutManager.getPosition(centerView);
            int targetPosition = -1;
            if (layoutManager.canScrollHorizontally()) {
                if (velocityX < 0) {
                    targetPosition = position - 1;
                } else {
                    targetPosition = position + 1;
                }
            }

            if (layoutManager.canScrollVertically()) {
                if (velocityY > 0) {
                    targetPosition = position + 1;
                } else …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview linearlayoutmanager

4
推荐指数
2
解决办法
5236
查看次数

从中心项目启动我的RecyclerView水平传送带

我正在创建一个旋转木马卧式RecyclerView,其焦点位于从RecyclerView的第一项开始的焦点项上。

自定义CenterZoomLayoutManager的代码:

public class CenterZoomLayoutManager extends LinearLayoutManager {
private final float mShrinkAmount = 0.15f;
private final float mShrinkDistance = 0.9f;

public CenterZoomLayoutManager(Context context, int orientation, boolean reverseLayout) {
    super(context, orientation, reverseLayout);
}

@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
    int orientation = getOrientation();
    if (orientation == HORIZONTAL) {

        int scrolled = super.scrollHorizontallyBy(dx, recycler, state);
        float midpoint = getWidth() / 2.f;
        float d0 = 0.f;
        float d1 = mShrinkDistance * midpoint;
        float s0 = 1.f;
        float s1 = …
Run Code Online (Sandbox Code Playgroud)

java android android-scroll android-recyclerview linearlayoutmanager

4
推荐指数
1
解决办法
2673
查看次数

如何以编程方式更改RecyclerView中项目的位置?

是否有一个具体的项目移动到特定位置的方式RecyclerView使用LinearLayoutManager编程方式?

android android-recyclerview linearlayoutmanager

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

具有起始偏移量的RecyclerView

我希望回收器视图中的第一个元素被开始列表抵消。 第一名 向下滚动时

我尝试使用

void onCreate(Bundle savedInstanceState){
...
    linearLayoutManager.scrollToPositionWithOffset
...
}
Run Code Online (Sandbox Code Playgroud)

但这行不通。我不明白我可以使用空视图如何在列表中零元素,但它不是完美的解决方案。

android android-recyclerview linearlayoutmanager

3
推荐指数
1
解决办法
4466
查看次数

RecyclerView 上 LinearLayoutManager 的 scrollToPositionWithOffset 不起作用

我正在尝试使用 制作粘性图像的水平列表,RecyclerView并且我想用scrollToPositionWithOffset. 我认为传递0asposition和我想向右/向左移动的像素为offset.

但它不起作用,列表保持不变,未滚动,它不动。这是我的实现:

final LargeImageAdapter mLargeImageAdapter = new LargeImageAdapter(this);
linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(mLargeImageAdapter);

seekBar = (SeekBar)findViewById(R.id.seekBar);
seekBar.setMax(7000);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        int scrollToDX = progress;

        ((LinearLayoutManager)recyclerView.getLayoutManager()).scrollToPositionWithOffset(0, scrollToDX);
        // tried invoking also linearLayoutManager instead getLayoutManager.
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
});
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

非常感谢。

问候。

拉斐尔。

android android-recyclerview linearlayoutmanager

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

Android RecyclerView 的平滑滚动不适用于初始滚动

我正在开发一款仅在一台运行 KitKat 的设备上运行的 Android 应用程序。

我使用的 RecylerView 的平滑滚动功能在其他物理平板电脑上运行,但 genymotion 不幸的是在它需要运行的一台设备上停止运行。

它不是滚动到某个位置,而是越过目标位置并一直滚动到底部,看起来非常糟糕。

我能够追踪 RecyclerView 类中抽象 SmoothScroller 的错误。

           if (getChildPosition(mTargetView) == mTargetPosition) {
                onTargetFound(mTargetView, recyclerView.mState, mRecyclingAction);
                mRecyclingAction.runIfNecessary(recyclerView);
                stop();
            } else {
                Log.e(TAG, "Passed over target position while smooth scrolling.");
                mTargetView = null;
            }
Run Code Online (Sandbox Code Playgroud)

我使用的是我在网上找到的 SnappingLinearLayoutManager,但将其换成了 Android 中的普通 LinearLayoutManager,但仍然遇到同样的问题。

该列表有 7 个项目长(用户一次可以看到 4 个项目),我滚动到第 5 个项目(位置 4)。

当我滚动到第三个时,我没有收到此错误。

此外,在我上下滚动列表一次后,错误就停止发生。

编辑: 我可以使用layoutManager.scrollToPositionWithOffset(); 但我正在尝试用平滑的滚动动画来做到这一点。

这是我的一些代码和详细信息:

private void setupMainRecyclerViewWithAdapter() {
    mainLayoutManager = new SnappingLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mainListRecyclerView.setLayoutManager(mainLayoutManager);

    settingsMainListAdapter = new SettingsListAdapter(SettingsActivity.this,
            settingsPresenter.getSettingsItems(),
            settingsPresenter);

    mainListRecyclerView.setAdapter(settingsMainListAdapter);

    mainListRecyclerView.addItemDecoration(new BottomOffsetDecoration(EXTRA_VERTICAL_SCROLLING_SPACE)); …
Run Code Online (Sandbox Code Playgroud)

android android-scroll android-recyclerview linearlayoutmanager

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

LinearLayoutManager.findViewByPosition() 返回 null

我的活动显示RecyclerView带有LinearLayoutManager. 我想获取View列表中的第一项 ( )。根据这篇文章接受的答案,我可以调用LinearLayoutManager.findViewByPosition()方法,但我得到了null。为什么?

RecyclerView list = findViewById(R.id.list);
LinearLayoutManager llm = new LinearLayoutManager(this);
list.setLayoutManager(llm);
MyAdapter adapter = new MyAdapter();
list.setAdapter(adapter);
View firstViewItem = llm.findViewByPosition(0); // <-- null
Run Code Online (Sandbox Code Playgroud)

adapter 包含项目,它不是空的。

android android-recyclerview linearlayoutmanager

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

RecyclerView具有空指针异常

我从CMS获取一些新闻数据,并希望在RecyclerView中显示它们.问题是我在使用LinearLayoutManager的行中得到一个空指针异常.这是logcat输出.

Caused by: java.lang.NullPointerException
  at testing.theo.manchesterunitedapp.newsandfeatures.FeaturesFragment.onCreateView(FeaturesFragment.java:65)
  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
  at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
  at android.app.Activity.performStart(Activity.java:5241)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:136) 
  at android.app.ActivityThread.main(ActivityThread.java:5001) 
  at java.lang.reflect.Method.invokeNative(Native Method) 
  at java.lang.reflect.Method.invoke(Method.java:515)
Run Code Online (Sandbox Code Playgroud)

我在做Web服务部分的片段非常简单.我用来回调方法.我正在初始化ArrayList和RecyclerView的onCreateView,其次是运行webservice的onActivityCreate.

public class FeaturesFragment extends Fragment {

public static final String TAG = "ManuApp";
private static final String IMAGE_URL = "xxxxxxxxxxxx/xxxx/features_images/" ;
private List<FeaturesObject> listItemsList;

private RecyclerView mRecyclerView;
private FeaturesAdapter adapter;

public FeaturesFragment() {
    // Required empty …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview linearlayoutmanager

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