Reputation: 371
I have a chat RecyclerView, and I want the ImageView to wrap different sizes. When the view loads for the first time it works fine, but on scroll the sizes changes. If possible i want to fit different sizes without losing control of width and height.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sentContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:clickable="true"
android:gravity="end"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/sentImgL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:padding="5dp"
android:background="@drawable/sent_img_bg"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.cardview.widget.CardView
android:id="@+id/receivedImgCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardCornerRadius="18dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:id="@+id/sentImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:maxWidth="250dp"
android:maxHeight="350dp"
android:scaleType="centerInside"
android:contentDescription="@string/todo"
android:cropToPadding="true"
android:src="@drawable/me_p" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dateSeenImgS"
android:text="@string/todo"
android:layout_margin="4dp"
android:layout_gravity="bottom|end"
android:textColor="@color/white" />
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 0
Views: 610
Reputation: 757
Override this two methods inside your RecyclerAdapter.
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
Upvotes: 0