我的Recyclerview是一个消息列表。RecyclerView项目wrap_content宽度
每个项目是一个线性布局,宽度为wrap_content
。
的问题是,当一个新项目被插入,该项目将如果它是更大的乘坐前一个项目的宽度(这使得它看起来像它有一个很大的填充)
我ViewHolder构造函数,但那些试图setRecycable(false)
造成了一些问题,我想用不同的方法。
任何帮助表示赞赏。 感谢
编辑:布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/message_date_layout"
layout="@layout/time_bubble"/>
<LinearLayout
android:id="@+id/message_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginEnd="30dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="30dp"
android:layout_marginStart="6dp"
android:background="@drawable/background_incoming_chat_bubble"
android:orientation="vertical"
android:padding="6dp">
//other views
</LinearLayout>
</LinearLayout>
CraeteViewHolder
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ChatMessagesAdapter.ViewHolder viewHolder;
LayoutInflater inflater = LayoutInflater.from(context);
View v = null;
switch (viewType) {
case OUTGOING:
v = inflater.inflate(R.layout.chat_bubble_outgoing, parent, false);
break;
case INCOMING:
v = inflater.inflate(R.layout.chat_bubble_incoming, parent, false);
break;
}
viewHolder = new ChatMessagesAdapter.ViewHolder(v);
return viewHolder;
}
请添加一些代码。 – FiN
@FiN编辑原始文章 – PampaZiya
你可以分享'chat_bubble_outgoing'和'chat_bubble_incoming'布局吗? – FiN