How show a Horizontal Recyclerview - have trouble showing horizontal items

horizontal recyclerview android example
how to scroll horizontal recyclerview programmatically?
horizontal recyclerview with two rows
horizontalscrollview inside recyclerview android
android recyclerview horizontal scroll animation
horizontal recyclerview android kotlin
multiple horizontal recyclerview android
horizontal recyclerview with indicator android

I want to show horizontal items in recyclerview, but I've tried but no work it all, only show me horizontal items with enlarge widh.

In Android Studio show as I want

But in runtime in my movile, show me

The items is width wraped but the other items appear after scroll right separated of my previus item.

This is my code.

LIST_ITEM

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">


    <LinearLayout
        android:id="@+id/linearFondo"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:background="@drawable/item_list_sel"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_gravity="center"
            app:srcCompat="@drawable/ruta"
            tools:srcCompat="@drawable/ruta" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tnombre"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:inputType="textMultiLine"
                android:lines="1"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textSize="12sp"
                android:textStyle="bold"></TextView>

            <TextView
                android:id="@+id/thorarios"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="@color/colorPrimary"
                android:textSize="10sp"
                android:visibility="gone"></TextView>

        </LinearLayout>

    </LinearLayout>
</LinearLayout>

And My Xml to show the recyclerview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="sitetech.NFCcheckPoint.ui.operador.CheckFragment">

    <!-- TODO: Update blank fragment layout -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@color/SuccessColor"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp">

            <TextView
                android:id="@+id/tfecha"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:text="Fecha"
                android:textSize="20sp" />

            <Button
                android:id="@+id/bpruebas"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Pasar Tarjeta" />

        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Ruta para el registro" />

        <com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
            android:id="@+id/rlista"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="#888"
            android:dividerHeight="0dp"
            android:fadeScrollbars="true"
            android:orientation="horizontal"
            android:overScrollMode="never"
            android:scrollbarAlwaysDrawHorizontalTrack="true"
            android:scrollbarAlwaysDrawVerticalTrack="false"
            android:scrollbars="horizontal"
            app:itemSpace="0dp"
            tools:listitem="@layout/ruta_sel_template">

        </com.omega_r.libs.omegarecyclerview.OmegaRecyclerView>

    </LinearLayout>
</LinearLayout>

And my Fragment code to load

dataAdapter = new rutaSelAdapter(lista, new onItemClick() {
            @Override
            public void onClickItemList(View v, int position) {
                ToastHelper.info(lista.get(position).getNombre().toString());
            }
        });

        rlista.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        rlista.setAdapter(dataAdapter);

And my dataAdapter class

public class rutaSelAdapter extends OmegaRecyclerView.Adapter<rutaSelAdapter.ViewHolder> {
    public List<Ruta> lista;
    private onItemClick onItemClick;
    private Ruta selectedItem;

    public rutaSelAdapter(List<Ruta> l, onItemClick onclick) {
        lista = l;
        this.onItemClick = onclick;
        if (l.size() > 0)
            setSelectedItem(l.get(0));
    }

    @Override
    public int getItemCount() {
        return lista.size();
    }

    @Override
    public rutaSelAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new rutaSelAdapter.ViewHolder(parent);
    }

    @Override
    public void onBindViewHolder(rutaSelAdapter.ViewHolder holder, int position) {
        Ruta dato = lista.get(position);
        holder.display(dato);
    }

    public void setSelectedItem(Ruta rx){
        selectedItem = rx;
    }

    public Ruta getSelectedItem(){
        return selectedItem;
    }

    public void updateData(Ruta bx) {
        boolean nuevo = true;
        for (Ruta rx : lista) {
            if (rx.getId() == bx.getId()) {
                lista.set(lista.indexOf(rx), bx);
                nuevo = false;
            }
            ToastHelper.info("Se a modificado el horario.");
        }

        if (nuevo) {
            lista.add(bx);
            ToastHelper.exito("Horario asignado.");
        }

        notifyDataSetChanged();
    }

    public void deleteData(Ruta rx) {
        //ToastHelper.normal("Se a eliminado el horario " + rx.getHora());
        lista.remove(rx);
        notifyDataSetChanged();
    }

    public class ViewHolder extends SwipeViewHolder implements View.OnClickListener {
        private final TextView tnombre;
        private LinearLayout linearFondo;
        HorarioDao horarioManager = AppController.daoSession.getHorarioDao();

        private Ruta currentItem;

        public ViewHolder(ViewGroup itemView) {
            super(itemView, R.layout.ruta_sel_template, SwipeViewHolder.NO_ID, SwipeViewHolder.NO_ID);

            tnombre = findViewById(R.id.tnombre);
            linearFondo = findViewById(R.id.linearFondo);
            contentView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setSelectedItem(currentItem);
                    onItemClick.onClickItemList(v, getAdapterPosition());
                }
            });
        }

        private Ruta backItem;
        private void setSelection(Ruta rx){
            //if (backItem == null)

        }

        @Override
        public void onClick(final View v) {

        }

        public void display(Ruta rx) {
            currentItem = rx;
            if (rx.getNombre() == null) tnombre.setText("");
            else tnombre.setText(rx.getNombre().toString());
        }
    }
}

In Android Studio show me right as I want.

But in runtime, in my mobile the items have full width but wrap content.enter image description here


i think you just add notifyDataSetChanged in your class adapter

public rutaSelAdapter(List<Ruta> l, onItemClick onclick) {
        lista = l;
        this.onItemClick = onclick;
        if (l.size() > 0)
            setSelectedItem(l.get(0));
        notifyDataSetChanged();
    }

java - How show a Horizontal Recyclerview, I want to show horizontal items in recyclerview, but I've tried but no work it all, only show me horizontal items with enlarge widh. In Android  Right click on res -> layout folder and then click on New –> Layout resource file menu item. A dialog box will open up; provide the File name as “horizontal_list_grocery_item” and click OK button. Add an imageview and textview in the layout file. This is the layout of how each item in list will look like.


In your recyclerview item layout update width of these 2 textviews [tnombre and thorarios] to wrap_content

<LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tnombre"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:inputType="textMultiLine"
                android:lines="1"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textSize="12sp"
                android:textStyle="bold"></TextView>

            <TextView
                android:id="@+id/thorarios"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="@color/colorPrimary"
                android:textSize="10sp"
                android:visibility="gone"></TextView>

        </LinearLayout>

Android Recipes: A Problem-Solution Approach, A Problem-Solution Approach Dave Smith, Erik Hellman. • LinearLayoutManager​: Place child views vertically (top to bottom) or horizontally (left to right) in a list. When you use a RecyclerView, you need to specify a LayoutManager that is responsible for laying out each item in the view. The LinearLayoutManager allows you to specify an orientation, just like a normal LinearLayout would. To create a horizontal list with RecyclerView, you might do something like this:


If someone else have this issue, I fixed adding this line in the fragment class.

rlista.setHasFixedSize(true);

Professional Android, ViewPager—Implements a horizontally scrolling set of Views. When you need to display a large dataset within your UI, it may be tempting to add hundreds of will lay out items from left to right and the Recycler View will scroll horizontally. This object positions the RecyclerView’s items and tells it when to recycle items that have transitioned off-screen. The ListView used to do this work alone. The RecyclerView has broken out this functionality to allow for different kinds of layouts: Vertical, horizontal, grid, staggered or your own! Layout Managers offer three choices by default:


Horizontal RecyclerView, Learning android development for complete beginners (FREE In this video I show you how to Duration: 22:47 Posted: Feb 12, 2018 So, if the RecyclerView has created a set of 7 views ready to display despite even if the data is way larger than that, and the viewport can fit 5, once the user starts scrolling, the 6th, and 7th come into the display while the views 1 and 2 exits the screen.


Android, It has been created to make possible construction of any lists with XML layouts as an item which can be customized vastly while improving on the efficiency of  Now we need to create Options Menu for RecyclerView Items. You can see the three vertical dots in every item. We will option the option on the click over this three vertical dot. Creating Options Menu for RecyclerView Item. Now the last phase of this tutorial is creating Options Menu for RecyclerView Item. So again come inside CustomAdapter.java.


Android Studio 3.2 Development Essentials, Once a new project has been created using the Master/Detail Flow template, a number <item>_list.xml – The layout file used to display the master This file contains a horizontal LinearLayout parent within which resides a RecyclerView to​  LinearLayoutManager: Displays items in a vertical or horizontal scrolling list. GridLayoutManager: Displays items in a grid. StaggeredGridLayoutManager: Displays items in a more staggered grid. RecyclerView.Adapter: Similar to the built-in Android ArrayAdapter. It will populate the data into the RecyclerView.