iosamammohamed
iosamammohamed

Reputation: 327

Issue with RecyclerView

I made a recycler view with linear layout manager to display items.

This is my RecyclerView.

<com.example.Recycler.RecyclerView
    android:id="@+id/recycler1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

And this is the item layout that I'm using for RecyclerView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:padding="5dp"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16dp"
        android:id="@+id/content"/>

</LinearLayout>

Everything works well, but I've got a small issue. The data which I fill the recycler with are 10 items.

The recycler in some devices displays the 10 items, in other devices, it displays only 3 items and make scrollbars to show the rest.

I tried to use android:scrollbars="none" in the recycler, but it made the recycler show only 3 items.

I tried also to use setNestedScrollingEnabled(false); but it didn't work either.

Any help?

Upvotes: 1

Views: 83

Answers (2)

Zarul Izham
Zarul Izham

Reputation: 591

You should make height for RecyclerView to match_parent.

Here is the code should be:

<com.example.Recycler.RecyclerView
    android:id="@+id/recycler1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Upvotes: 1

Ferdous Ahamed
Ferdous Ahamed

Reputation: 21766

Use RecyclerView android.support.v7.widget.RecyclerView instead of your custom com.example.Recycler.RecyclerView

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler1"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v7.widget.RecyclerView>

The RecyclerView widget is a part of the v7 Support Libraries. To use this widget in your project, add below Gradle dependency to your app's module:

dependencies {
    ...
    compile 'com.android.support:recyclerview-v7:25.0.+'
}

Upvotes: 1

Related Questions