Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding horizontal scrolling to chip group in Relative layout

I created few static chips in a group. I'm using this link (https://material.io/design/components/chips.html#) as reference. Code is as given below:

<RelativeLayout
        android:id="@+id/inputLayout"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        android:gravity="bottom"
        android:paddingStart="8dp"
        android:paddingTop="8dp"
        android:paddingEnd="8dp"
        android:paddingBottom="9dp">

        <ImageView
            android:id="@+id/sendBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:paddingTop="4dp"
            app:srcCompat="@drawable/chatbot_send_btn" />

        <EditText
            android:id="@+id/queryEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_toStartOf="@+id/sendBtn"
            android:imeOptions="actionSend"
            android:inputType="text"
            android:paddingTop="4dp"
            android:textSize="18sp" />

        <com.google.android.material.chip.ChipGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:layout_above="@id/queryEditText">

            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd" />

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd"
                style="@style/Widget.MaterialComponents.Chip.Choice"/>

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd"
                style="@style/Widget.MaterialComponents.Chip.Choice"/>

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd"
                style="@style/Widget.MaterialComponents.Chip.Choice"/>

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd"
                style="@style/Widget.MaterialComponents.Chip.Choice"/>

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd" />

        </com.google.android.material.chip.ChipGroup>

    </RelativeLayout>  

This doesn't display all chips, it displays only 1 chip. How can I add hoizontal scrolling? do I need to display chips dynamically so that I can add horizontal scrolling?

like image 914
Ajay Kulkarni Avatar asked Jan 04 '19 07:01

Ajay Kulkarni


People also ask

How do you implement horizontal scrolling?

Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.

What is horizontal scrolling?

Horizontal scrolling is the ability of a program to allow a user to scroll horizontally using the window scroll bar. The horizontal scroll bar is not used often and usually not visible or not accessible because it is not needed.

What is the difference between ScrollView and horizontal ScrollView?

Attributes Of Scroll View: ScrollView and HorizontalScrollView has same attributes, the only difference is scrollView scroll the child items in vertical direction while horizontal scroll view scroll the child items in horizontal direction.


2 Answers

just put on horizontalScrollView and set android:scrollbars="none"

   <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none">

            <com.google.android.material.chip.ChipGroup
                android:id="@+id/chipsPrograms"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:paddingStart="8dp"
                android:paddingEnd="8dp"
                app:chipSpacing="8dp"
                app:singleSelection="true" />
        </HorizontalScrollView>
like image 169
Vishal Nagvadiya Avatar answered Sep 28 '22 05:09

Vishal Nagvadiya


You can put the ChipGroup inside an HorizontalScrollView

like image 42
Jassem Ben Hamida Avatar answered Sep 28 '22 05:09

Jassem Ben Hamida