Recyclerview는 메시지 목록입니다.RecyclerView items wrap_content width
각 항목은 너비가 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 onBindViewHolder
의 끝 라인에 holder.setIsRecyclable(false);
를 사용 또한이
@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, null, false);
break;
case INCOMING:
v = inflater.inflate(R.layout.chat_bubble_incoming, null, false);
break;
}
viewHolder = new ChatMessagesAdapter.ViewHolder(v);
return viewHolder;
}
와 위
@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