How to reduce space between RecyclerView elements in Android?

I applied Horizontal RecyclerView for images. Horizontal navigation works fine, but unwanted space is drawn between the two RecyclerView elements.

Unwanted space on the left side of the image element in RecyclerView Unwanted space between two images in RecyclerView

RecyclerView Element Layout -

<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="match_parent" > <ImageView android:id="@+id/imgView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/ic_launcher" /> </LinearLayout> 

My RecyclerView layout is

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> 

RecyclerView Setting -

 recyclerView = (RecyclerView) findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); HlistViewAdapter adapter = new HlistViewAdapter(pArray); recyclerView.setAdapter(adapter); recyclerView.setItemAnimator(new DefaultItemAnimator()); 

My RecyclerView adapter is

 public class HlistViewAdapter extends RecyclerView.Adapter<HlistViewAdapter.ViewHolder>{ ArrayList<String> pathArray; public HlistViewAdapter(ArrayList<String> pathArray){ this.pathArray = pathArray; } @Override public HlistViewAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View itemLayoutView = LayoutInflater.from(viewGroup.getContext()) .inflate(R.layout.hlist_item_layout, null); // create ViewHolder ViewHolder viewHolder = new ViewHolder(itemLayoutView); return viewHolder; } @Override public void onBindViewHolder(HlistViewAdapter.ViewHolder viewHolder, int i) { viewHolder.imgViewIcon.setImageBitmap(BitmapFactory.decodeFile(pathArray.get(i))); } public static class ViewHolder extends RecyclerView.ViewHolder { public ImageView imgViewIcon; public ViewHolder(View itemLayoutView) { super(itemLayoutView); imgViewIcon = (ImageView) itemLayoutView.findViewById(R.id.imgView); } } @Override public int getItemCount() { return pathArray.size(); } } 
+1
source share
1 answer

edited response after chat with user

the problem was that the size of the images is too different for different Android devices and the inability to stretch them to prevent empty spaces. considering that I recommend using ViewPager instead of RecyclerView, having the same functionality, but with better control over how the image will respond to images of different sizes.

http://codetheory.in/android-image-slideshow-using-viewpager-pageradapter/

+1
source

Source: https://habr.com/ru/post/1238082/


All Articles