Search code examples
androidandroid-scrollviewandroid-constraintlayout

Android horizontal scrollview not scrolling


I have include the scroll view in a horizontal way as follows but it not scrolling. Cannot find the issue. Cant we create a scroll view within ConstraintLayout?

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                             xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
                                             android:layout_height="match_parent"
                                             xmlns:app="http://schemas.android.com/apk/res-auto">

    <ScrollView
                android:id="@+id/colors_scrollview"
                android:layout_width="250dp"
                android:layout_height="48dp"
                app:layout_constraintBottom_toTopOf="@+id/navigation"
                android:orientation="horizontal">

            <LinearLayout android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:orientation="horizontal">

                <View
                        android:layout_width="148dp"
                        android:clickable="true"
                        android:layout_height="48dp"
                        android:background="#2196F3" />

                <View
                        android:layout_width="148dp"
                        android:clickable="true"
                        android:layout_height="48dp"
                        android:background="#FFC107" />
           </LinearLayout>

     </ScrollView>
</android.support.constraint.ConstraintLayout>

Solution

  • If you want horizontal scrolling, you may use <HorizontalScrollView> </HorizontalScrollView> tags instead of <ScrollView>.