标签: recyclerview-layout

实施滑动以刷新布局后,Recycler视图无法正确滚动

在执行刷卡刷新视图之前,回收器视图工作正常但不是每当我尝试向下滚动回收器视图时刷卡刷新干扰并阻碍滚动运动.

以下是该问题的屏幕截图:

(注意,当回收器视图向下滚动时,滑动刷新布局会出现)

在此输入图像描述

这是我的布局片段:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/activity_main_swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:wheel="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/availableTaskRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />
    <RelativeLayout
        android:id="@+id/progress_wheel"
        android:visibility="gone"
        tools:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal|center_vertical"
        android:background="@color/transparentLoaderBackground">

        <com.pnikosis.materialishprogress.ProgressWheel
            android:layout_width="50dp"
            android:layout_height="50dp"
            wheel:matProg_barColor="@color/white"
            wheel:matProg_barWidth="1dp"
            wheel:matProg_progressIndeterminate="true"/>
    </RelativeLayout>


    <RelativeLayout
        android:id="@+id/no_available_tasks"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        tools:visibility = "visible"
        >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="No tasks currently available. Pull to refresh"
            android:layout_centerInParent="true"
            android:padding="16dp"
            android:gravity="center_horizontal"
            android:textSize="18sp"/>

    </RelativeLayout>

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

下面是我片段的代码:

package com.packrboy.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import …
Run Code Online (Sandbox Code Playgroud)

android swiperefreshlayout android-recyclerview recyclerview-layout

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

在滚动完成之前,Recyclerview不能平滑滚动

我有滚动问题.我的意思是滚动速度很快,但在滚动完成之前看起来像是滞后.在这里我定义__CODE__:

RecyclerView recyclerView=fragment.getRecyclerView();
        LinearLayoutManager layoutManager = new LinearLayoutManager(fragment.getActivity(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new DividerItemDecoration(fragment.getActivity(), LinearLayoutManager.VERTICAL));
 ArrayList<InstaPostModel> rowListItems=getInstaPostListSample();
        InstaPostAdapter rcAdapter = new InstaPostAdapter(rowListItems);
        recyclerView.setAdapter(rcAdapter);
Run Code Online (Sandbox Code Playgroud)

这是__CODE__.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final InstaPostModel p = items.get(position);
    context = holder.itemView.getContext();
    Glide.with(context).load(R.mipmap.mee_small).into(holder.userPhoto);
    Glide.with(context).load(R.drawable.post_image).into(holder.photo_content);
    Glide.with(context).load(R.mipmap.love_gray_icon).into(holder.bt_like);
    Glide.with(context).load(R.mipmap.comment_icon).into(holder.bt_comment);
    Glide.with(context).load(R.mipmap.share_icon).into(holder.bt_share);

    holder.userNameTextView.setText(p.getPosterUserName());
    holder.postContent.setText(p.getText());
    holder.post_date.setReferenceTime(p.getDate().getTime());
}
Run Code Online (Sandbox Code Playgroud)

这是 __CODE__

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

    <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/qatar_now_posts_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        tools:context=".uis.fragments.home.QatarNowFragment"
        />
Run Code Online (Sandbox Code Playgroud)

编辑

我有一个底部导航栏__CODE__,它在滚动时显示.

编辑2

这是显示滞后的视频链接.

编辑3

也许我在测试应用程序时发现了问题.我看到图表和应用程序从Ram内存大约120 MB,但仍然不知道如何解决这个问题.

编辑4

__CODE__ 类 …

android smooth-scrolling recycler-adapter android-recyclerview recyclerview-layout

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

没有间隙策略时,RecyclerView的内容不可见

我有一个RecyclerView用来显示2列布局的图表,其中某些项目作为部分使用全宽显示。这就是我设置我的方式RecyclerView

StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
recyclerView.setItemAnimator(null);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new SpacesItemDecoration(Utils.dpToPx(8)));
Run Code Online (Sandbox Code Playgroud)

这是我的SpaceItemDecoration课:

private class SpacesItemDecoration extends RecyclerView.ItemDecoration {
        private int space;

        public SpacesItemDecoration(int space) {
            this.space = space;
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            int position = parent.getChildAdapterPosition(view);
            int viewType = adapter.getItemViewType(position);
            if (viewType == 1) {
                //this is the regular view type
                if (map.get(position)) {
                    //it is on the left side
                    outRect.right = space / …
Run Code Online (Sandbox Code Playgroud)

android staggered-gridview android-recyclerview recyclerview-layout

8
推荐指数
0
解决办法
661
查看次数

如何防止RecyclerView单元的子项在用户滚动时移动

我的水平 线上有很长的单元格RecyclerView,我希望它们有一个在用户水平滚动时保持静止的标题.

- Recycler View (A)
-   -   Cell (parent) (B)
-   -   -   Header (C) <-- We want that to be still
-   -   -   Content (D)
Run Code Online (Sandbox Code Playgroud)

这是它在视觉上的样子:

因此,我正在寻找一种方法:

1)当用户在(A)上拖动手指时,停止标题(C)改变位置RecyclerView

要么

2)像正常一样滚动单元格(B),但将其子项(C)的位置改为相反方向,以使标题即使在移动时也显示为静止(在父项的相反方向(B) .

这是我正在尝试构建的内容:

有任何想法吗?

ps 1:我注意到很多SO答案,建议使用ItemDecoration,但所有可能的答案都有VERTICAL实现代码,这与HORIZONTAL实现非常不同.

ps 2我正在以编程方式创建所有视图内容,因此我不会使用布局文件.(那是因为内容将是反应原生视图,我无法创建具有布局文件的内容).

ps 3:我也注意到这ItemDecoration是旧策略,最近的第三方库扩展了LayoutManager.

请稍微说清楚,谢谢.

android listview android-layout android-recyclerview recyclerview-layout

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

recyclerview中的最后一项被切断

我使用recyclerview显示项目列表,约束布局是父视图.布局显示如下:

  <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout
        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:orientation="vertical"
        android:layout_height="match_parent">

        <!-- Load the toolbar here -->
        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:fitsSystemWindows="true"
            android:minHeight="?android:attr/actionBarSize"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="@color/colorPrimary"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:visibility="visible"
            app:layout_constraintTop_toBottomOf="@+id/toolbar" />

        <ImageView
            android:id="@+id/imageViewContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toTopOf="parent"
            android:visibility="gone"
            android:src="@drawable/empty_category"/>

        <TextView
            android:id="@+id/textViewContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="center"
            android:text="Empty Category"
            android:textStyle="bold"
            android:textColor="@color/colorPrimary"
            android:textAppearance="@style/TextAppearance.AppCompat.Large"
            android:visibility="gone"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/imageViewContent" />

    </android.support.constraint.ConstraintLayout>

The adapter layout for each row is presented below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"> …
Run Code Online (Sandbox Code Playgroud)

xml android android-layout recyclerview-layout

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

RecyclerView没有滚动到底部

我遵循了recyclerview指南并为我正在制作的应用程序构建了一个,但由于某种原因它不会滚动到底部.我将它与谷歌代码片段以及其他在线代码片段进行了比较,看不出差异.我发布了一张图片和我正在使用的代码.我正在使用制表符,因此recyclerview填充在片段中.

该应用程序的外观如下:

http://imgur.com/H5uOLFR

适配器类:

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<Group> groups;

// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public class ViewHolder extends RecyclerView.ViewHolder {
    // each data item is just a string in this case
    public TextView groupName;
    public TextView groupDate;
    public TextView groupLocation;
    public …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-recyclerview recyclerview-layout

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

如何在协调器父级滚动Recycler视图上显示/隐藏FAB

我有一个协调器layout.inside活动的活动有一个片段与Recycler视图和浮动按钮.我可以显示/隐藏浮动按钮当Scroll Recycler查看并避免使用fab行为?!

在活动布局中:CoordinatorLayout -----> AppBarLayout ---->工具栏和FrameLayout以及底栏视图

在片段布局中:RelativeLayout ----> Recycler视图和float按钮

我想实现像Google+主页这样的内容.我该如何实现这种情况?


临时我用这个解决方案解决了我的问题:

使用我的片段中的接口的活动协调器布局和使用fab行为显示/隐藏fab ...直到我找到更好的解决方案!

android floating-action-button android-recyclerview recyclerview-layout

7
推荐指数
3
解决办法
9175
查看次数

在回收者视图中跳过项目

嗨,我想从中跳过一些项目recyclerview

这是屏幕截图

这是一些代码

item_Data.xml

 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:id="@+id/mainlayout"
android:layout_height="wrap_content">
<ImageView
    android:visibility="gone"
    android:id="@id/image"
    android:layout_gravity="center"
    android:layout_width="100dp"
    android:layout_height="100dp" />
<TextView
    android:visibility="gone"
    android:textStyle="bold"
    android:id="@id/title"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:maxLength="15" />
Run Code Online (Sandbox Code Playgroud)

回收者视图是

   @Override
public void onBindViewHolder(final MovieViewHolder holder, final int position) {
    String download= news.get((position)).getDownloadLinkForApkNew();
    String desc_new = news.get(position).getApkJData();
    if (download.isEmpty()==false && desc_new.isEmpty()==false) {
        holder.movieTitle.setVisibility(View.VISIBLE);
        holder.imageView.setVisibility(View.VISIBLE);
        Picasso.with(context).load(news.get((position)).getBetterFeaturedImage().getSourceUrl()).into(holder.imageView);
        holder.movieTitle.setText(news.get(position).getTitle().getRendered());
    }
Run Code Online (Sandbox Code Playgroud)

我不希望没有下载和desc_new的项目。我的逻辑作品不可见,但它们留有空间。如何删除项目之间的空格。

layout android android-recyclerview recyclerview-layout

7
推荐指数
2
解决办法
4169
查看次数

RecyclerView反向无限滚动

我正在创建一个聊天应用程序,并且试图以相反的方式实现RecyclerView的无尽滚动,例如从底部开始并向上滚动,直到到达顶部时才加载更多内容。

当用户打开聊天屏幕时,该应用会获取最后20条消息,并且默认情况下滚动到底部。当用户向上滚动时,我想从服务器获取更多消息。

以下是我正在测试的通用无穷滚动代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        layoutManager = new LinearLayoutManager(this);
        recyclerView =  (RecyclerView)findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);


        adapter = new RecyclerViewAdapter<String, ItemViewHolder>(String.class,R.layout.item,ItemViewHolder.class,list) {
            @Override
            protected void populateViewHolder(ItemViewHolder viewHolder, String model, int position) {
                if(model != null){
                    viewHolder.textView.setText(model);
                }
            }
        };
        recyclerView.setAdapter(adapter);
        recyclerView.setOnScrollListener(new EndlessReverseRecyclerViewScrollListener(layoutManager) {
            @Override
            public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
                loadMore();
            }
        });
        loadInit();
    }

    private void loadInit(){
        for(int x = 0; x < 20;x++){
            list.add(list.size()+": "+getRandomString(8));
            adapter.notifyDataSetChanged();
        }
        layoutManager.scrollToPosition(list.size() -1);
    }

    private void …
Run Code Online (Sandbox Code Playgroud)

java android android-recyclerview recyclerview-layout

7
推荐指数
2
解决办法
2641
查看次数

ChildHelper.java 第 352 和 355 行崩溃

我们的应用程序有一个使用 RecyclerView 构建的 listView,并且可以在不同的用例上添加、删除、移动、更改项目,并且我使用默认动画

Android 中有 1000 个与 ChildHelper 类相关的崩溃,导致应用程序崩溃的代码如下,可在https://android.googlesource.com/platform/frameworks/support/+/5031b30/v7/recyclerview/src上找到/android/support/v7/widget/ChildHelper.java#352

void unhide(View view) {
        final int offset = mCallback.indexOfChild(view);
        if (offset < 0) {
            throw new IllegalArgumentException("view is not a child, cannot hide " + view);
        }
        if (!mBucket.get(offset)) {
            throw new RuntimeException("trying to unhide a view that was not hidden" + view);
        }
        mBucket.clear(offset);
        unhideViewInternal(view);
    }
Run Code Online (Sandbox Code Playgroud)

可能导致这两个错误的用例是什么以及我们如何避免这些错误?

这是两种情况的崩溃日志。

选择未隐藏的视图持有者情况下的崩溃日志。

Fatal Exception: java.lang.RuntimeException: trying to unhide a view that was not hiddenandroid.widget.FrameLayout{dd0c169 V.E...... ......ID 0,54-680,234}
   at android.support.v7.widget.ChildHelper.unhide(ChildHelper.java:355)
   at android.support.v7.widget.RecyclerView$Recycler.getScrapOrHiddenOrCachedHolderForPosition(RecyclerView.java:6124) …
Run Code Online (Sandbox Code Playgroud)

crash android android-recyclerview recyclerview-layout

7
推荐指数
0
解决办法
1949
查看次数