【问题标题】:Getting gaps between recyclerview items after scrolling down and then scrolling up again. Please see details向下滚动然后再次向上滚动后,recyclerview 项目之间出现间隙。请看详情
【发布时间】:2016-10-26 06:45:11
【问题描述】:

我有一个RecyclerView,我正在从数据库中加载一些项目。

问题是再次向下和向上滚动后,项目之间出现了一些间隙。然后差距一直存在,直到我重新启动应用程序。像这样:

这是我在 xml 布局中设置 recyclerview 的方法:

<android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

这是我在MainActivity.java 文件中的设置方式:

recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(fastItemAdapter);

这是适配器:

public class HRequest extends AbstractItem<HRequest, HRequest.ViewHolder> {

        public String imageURL;

        public HRequest() {

        }

        public HRequest(String imageURL) {
            this.imageURL = imageURL;
        }

        // Fast Adapter methods
        @Override
        public int getType() {
            return R.id.recycler_view;
        }
        @Override
        public int getLayoutRes() {
            return R.layout.h_request_list_row;
        }
        @Override
        public void bindView(ViewHolder holder) {
            super.bindView(holder);

            holder.imageURL.setText(imageURL);

        }
        // Manually create the ViewHolder class
        protected static class ViewHolder extends RecyclerView.ViewHolder {

            TextView imageURL;

            public ViewHolder(View itemView) {
                super(itemView);
                imageURL = (TextView)itemView.findViewById(R.id.imageURL);

if (!imageURL.getText().toString().isEmpty()) {

if (imageURL.getText().toString().startsWith("https://firebasestorage.googleapis.com/") || imageURL.getText().toString().startsWith("content://")) {
                    Picasso.with(itemView.getContext())
                            .load(imageURL.getText().toString())
                            .into(homelessImage);
                } else {
                    Toast.makeText(itemView.getContext(), "some problem", Toast.LENGTH_SHORT).show();
                }

            } else {
                Toast.makeText(itemView.getContext(), "no imageUID found", Toast.LENGTH_SHORT).show();
            }

            }
        }

    }

这里有什么问题?

请告诉我。

【问题讨论】:

  • 你能发布你的适配器吗?
  • 请检查更新的问题
  • 我在您的代码中没有发现任何问题。基本适配器类和项目布局的帖子代码,可能包含一些错误。
  • @HammadNasir post xml of this layout R.layout.h_request_list_row ...也尝试固定父布局的高度..
  • @WaqarYounis 和 Wax,你也可以看看这个:stackoverflow.com/questions/37977521/…PLEASE?..

标签: android android-layout android-recyclerview linearlayoutmanager


【解决方案1】:

在添加适配器之前添加:-

recyclerView.setLayoutManager(new LinearLayoutManager(this));

【讨论】:

    猜你喜欢
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多