Such problems: I load pictures into RecyclerView , but they do not scale to height (i.e., the width is compressed, but the height remains original) and the pictures become elongated. Regular ImageView scaled (when width is limited, height is reduced accordingly).

Question: what did I miss here?

I tried to manually set the LayoutParams for the ViewHolder and for the ImageView , changed the width, height and type of scaleType in the markup - it does not help.

My markup:

 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/gallery_list" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> <android.support.v4.view.ViewPager android:id="@+id/gallery_pager" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="5"/> </LinearLayout> 

My RecyclerViewAdapter

  public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> { private List<Card> cards; RecyclerViewAdapter(List<Card> cards) { this.cards = cards; } @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recyclerview_item, viewGroup, false); return new ViewHolder(v); } @Override public void onBindViewHolder(ViewHolder viewHolder, int i) { Card card = cards.get(i); viewHolder.img.setBackgroundResource(card.getImage()); } @Override public int getItemCount() { return cards.size(); } class ViewHolder extends RecyclerView.ViewHolder { private ImageView img; ViewHolder(View itemView) { super(itemView); img = (ImageView) itemView.findViewById(R.id.recycler_item_img); } } } 

My recycler_item_img

 <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/recycler_item_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" /> 

    1 answer 1

    viewHolder.img.setBackgroundResource(card.getImage()); in the line viewHolder.img.setBackgroundResource(card.getImage());

    You must viewHolder.img.setImageResource(card.getImage());