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

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(); } }
source share