There is a dialogue choosing avatars. The first time I have it enter image description here

Next, scroll 1 row below. I have:

enter image description here

Returning 1 row up (back):

enter image description here

That is, the problem is that the first displayed images are for some reason smaller than any images that will become visible after the scroll. How to cope with it? ..

Adapter

public class AvaChooseRecyclerAdapter extends RecyclerView.Adapter<AvaChooseRecyclerAdapter.AvaViewHolder> { private static final String TAG = "AvaChooseAdapter"; List<Integer> resourceIds = Arrays.asList( R.drawable.avatars_01, R.drawable.avatars_02, R.drawable.avatars_03, R.drawable.avatars_04, R.drawable.avatars_05, R.drawable.avatars_06, R.drawable.avatars_07, R.drawable.avatars_08, R.drawable.avatars_09, R.drawable.avatars_10, R.drawable.avatars_11, R.drawable.avatars_12, R.drawable.avatars_13, R.drawable.avatars_14, R.drawable.avatars_15, R.drawable.avatars_16, R.drawable.avatars_17, R.drawable.avatars_18, R.drawable.avatars_19, R.drawable.avatars_20, R.drawable.avatars_21, R.drawable.avatars_22, R.drawable.avatars_23, R.drawable.avatars_24, R.drawable.avatars_25, R.drawable.avatars_26, R.drawable.avatars_27, R.drawable.avatars_28, R.drawable.avatars_29, R.drawable.avatars_30, R.drawable.avatars_31, R.drawable.avatars_32, R.drawable.avatars_33, R.drawable.avatars_34, R.drawable.avatars_35, R.drawable.avatars_36, R.drawable.avatars_37, R.drawable.avatars_38, R.drawable.avatars_39, R.drawable.avatars_40, R.drawable.avatars_41, R.drawable.avatars_42, R.drawable.avatars_43, R.drawable.avatars_44, R.drawable.avatars_45, R.drawable.avatars_46, R.drawable.avatars_47, R.drawable.avatars_48, R.drawable.avatars_49, R.drawable.avatars_50, R.drawable.avatars_51, R.drawable.avatars_52, R.drawable.avatars_53, R.drawable.avatars_54, R.drawable.avatars_55, R.drawable.avatars_56, R.drawable.avatars_57, R.drawable.avatars_58, R.drawable.avatars_59, R.drawable.avatars_60, R.drawable.avatars_61, R.drawable.avatars_62, R.drawable.avatars_63, R.drawable.avatars_64, R.drawable.avatars_65, R.drawable.avatars_66); public static class AvaViewHolder extends RecyclerView.ViewHolder { public ImageView iv; public AvaViewHolder(View itemView) { super(itemView); iv = (ImageView) itemView.findViewById(R.id.ava_item_imageview); } } @Override public AvaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.ava_item, parent, false); v.setPadding(4, 4, 4, 4); return new AvaViewHolder(v); } @Override public void onBindViewHolder(AvaViewHolder holder, int position) { Log.d(TAG, "onBindViewHolder position: " + position + " | holder obj:" + holder.toString()); holder.iv.setScaleType(ImageView.ScaleType.FIT_CENTER); holder.iv.setImageResource(resourceIds.get(position)); } @Override public int getItemCount() { return resourceIds.size(); } 

Markup

  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ava_item" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/ava_item_imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:adjustViewBounds="true"/> </FrameLayout> 
  • Show the adapter code, preferably a place where you set the size of the pictures or twist - Vitalii Obideiko
  • And hml (R.id.ava_item_imageview) - Vitalii Obideiko

2 answers 2

The problem is that you are using android:layout_width="wrap_content" android:layout_height="wrap_content" Try setting the exact size to DP, for example 40dp height and width. This should solve the problem, if you need to vary the size depending on the screen, then calculate the size before creating the adapter and set it programmatically for images

Example

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ava_item" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/ava_item_imageview" android:layout_width="40dp" android:layout_height="40dp"/> </FrameLayout> 
  • and how to calculate the size before creating the adapter? - Evgeny GooDi
  • @EvgenyGooDi for example, you can get the screen size (width), for example, take 1/4 of this size and set it to twist - Vitalii Obideiko
  • where in the code to do it right? I try in the activation code before assigning the adapter to the list. but I don’t understand how to transfer the calculated value to the adapter for setting the size ... - Evgeny GooDi
  • for example, through the adapter's setIconsSize (int) do and set before installing the adapter on the sheet - Vitalii Obideiko

To get the same VectorDrawable maximum size when used in a vertical-scrolling RecyclerView, you need to set the following at the root element:

 android:layout_width="match_parent" android:layout_height="wrap_content" 

I believe that for horizontal scrolling the parameters must be changed to the opposite.