• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

RecyclerView Horizontal No Scroll Shows 1 Item

snowman24

Newbie
Oct 18, 2017
17
0
I have created a recyclerview that list items horizontally with not scrolling applied. The problem is that only 1 item of the list is displayed.

main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:background="@color/cardview_dark_background"
    tools:context="com.yaadspice.my.Activity.MainActivity">

<android.support.v7.widget.RecyclerView
        android:id="@+id/slotVewID"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_marginBottom="346dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp" " />

</android.support.constraint.ConstraintLayout>


slots.xml
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/slottextID"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="TextView" />
        </RelativeLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

The only way I have been able to get all items to show up is allowing horizontal scrolling in my layout manager, which I do not want.

mainactivity
Code:
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

LinearLayoutManager slotmanager= new LinearLayoutManager(this);
//slotmanager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerViewSlot=(RecyclerView)findViewById(R.id.slotVewID);
        recyclerViewSlot.setLayoutManager(slotmanager);
        slotAdpater=new SlotAdpater(this, g.slotList);
        recyclerViewSlot.setAdapter(slotAdpater);
    }
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones