0

i am trying to add horziental scrolling to each row inside a vertical RecycleView ,the vertical scrolling works as expected but horizentalScrolling doesn't of each row

here is my code for the layout of recycleView

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

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

</LinearLayout>

and the layout of each row

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:clickable="true"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"

            android:gravity="center"
            android:text="1"
            android:textColor="#ffffff"
            android:textSize="@dimen/textSizeLarge"
            android:textStyle="bold" />

        <me.test.com.myCustomView
            android:id="@+id/myCustomView"
            android:layout_width="1000dp"
            android:layout_height="50dp" />
    </LinearLayout>
</HorizontalScrollView>

i tried adding horizantalScrollView but didn't work ,

2 Answers2

0

try to get a LinearLayoutManager and set it Horizontal and wrap your recyclerView in it like this.

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

LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
reclyclerView.setLayoutManager(layoutManager);
recyclerView.setMinimumWidth(200);
jboisjoli
  • 99
  • 1
  • 10
0

my problem was because of my custom View ,i override onMeasure() as suggested in this answer onMeasure custom view explanation and it works

Community
  • 1
  • 1