Search code examples
androidandroid-recyclerviewhorizontalscrollview

Recycler view inside Horizontal scroll view not work in android oreo but is working perfectly in below versions


the code below does not work for the oreo version android but is working is other versions . i am trying to use horizontal scroll view in this case a user must be able to comment and the other comments is shown by help of recycler view.so i have a problem in this code only for the new version of android .can anyone suggest me ideas regarding the issue. here is the code

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none">
    <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:orientation="horizontal">
        <FrameLayout
            android:layout_width="200dp"
            android:layout_height="175dp"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="5dp"
            android:background="@layout/button_background"
            android:layout_marginTop="15dp"
            >
            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/userfbpic1"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginTop="10dp"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginStart="15dp"
                android:src="@drawable/bg"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/current_username"
                android:text="@string/current_username_forcomment"
                android:layout_marginTop="12dp"
                android:layout_marginStart="50dp"
                android:textStyle="bold"
                android:textColor="@color/background"
                android:textSize="15sp"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="60dp">
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/background"
                    android:id="@+id/comments"
                    android:textSize="15sp"
                    android:hint="comment here"
                    android:imeOptions="actionDone"
                    android:singleLine="true"
                    android:textStyle="bold"
                    android:background="@android:color/transparent"
                    />
            </LinearLayout>
        </FrameLayout>
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview_comments"
                android:layout_width="wrap_content"
                android:nestedScrollingEnabled="false"
                android:layout_marginTop="15dp"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
            </android.support.v7.widget.RecyclerView>
   </LinearLayout>
</HorizontalScrollView>

Solution

  • When you put a RecyclerView inside a ScrollView of the same orientation the RecyclerView will extend, inflating and putting out all of his children inside the ScrollView becoming unscrollable. When you drag the view the RecyclerView consumes touch events and the ScrollView won't scroll, unless you disable RecyclerView touch..