滚动时CardViews之间的间隙增加 [英] Gap between CardViews increases on scrolling

查看:71
本文介绍了滚动时CardViews之间的间隙增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将CarViews与RecyclerView一起使用,加载时看起来不错,但是一旦滚动列表,CardViews之间的间隙就会增加,并且视图中一次只显示一张卡片.

I'm using CarViews with RecyclerView and it looks fine when loaded but once when the list is scrolled the gap between the CardViews increases and there shows only one card in the view at a time.

这是我的CardView.xml

Here is my CardView.xml

<LinearLayout 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.v7.widget.CardView
        android:id="@+id/conversationCard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp">

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

            <TextView
                android:id="@+id/abstractConvo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="35dp"/>

        </RelativeLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

这就是我使用该视图的方式

and here is how I'm using that view

    public class ConversationsListAdapter extends RecyclerView.Adapter<ConversationsListAdapter.ConversationsListViewHolder> {

    List<Conversation> conversationList;

    public ConversationsListAdapter(List<Conversation> conversationList) {
        this.conversationList = conversationList;
    }

    @Override
    public int getItemCount() {
        return conversationList.size();
    }

    @Override
    public ConversationsListViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.conversation_card, viewGroup, false);
        ConversationsListViewHolder listViewHolder = new ConversationsListViewHolder(view);
        return  listViewHolder;
    }

    @Override
    public void onBindViewHolder(ConversationsListViewHolder holder, int position) {
        holder.sender.setText(conversationList.get(position).getSenderPhNo());
        holder.abstractConvo.setText(conversationList.get(position).getAbstractConvo());
    }

    public static class ConversationsListViewHolder extends RecyclerView.ViewHolder {
        CardView cv;
        TextView abstractConvo, sender;

        public ConversationsListViewHolder(View itemView) {
            super(itemView);
            cv = (CardView) itemView.findViewById(R.id.conversationCard);
            sender = (TextView) itemView.findViewById(R.id.sender);
            abstractConvo = (TextView) itemView.findViewById(R.id.abstractConvo);
        }
    }
}

这是滚动列表之前的屏幕截图

Here is the screenshot before the list is scrolled

以及滚动后

谢谢.

推荐答案

根目录布局使用wrap_content

the root layout use wrap_content

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

这篇关于滚动时CardViews之间的间隙增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆