Search code examples
androidlistviewhorizontalscrollview

How to add horizontal scroll view below a listview


How to put a horizontal scrollview below a listview? I have a listview and below it a horizontal scroll view with a bunch of radio buttons. This is my code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/radioGroup">
    </ListView>

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:checked="true"
            android:gravity="center"
            android:padding="5dp"
            android:text="/>

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:padding="5dp"
            android:text="A-"/>


        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:padding="5dp"
            android:text="B+"/>

        <RadioButton
            android:id="@+id/bNegative"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:padding="5dp"
            android:text="/>

    </RadioGroup>

</RelativeLayout>

I need to be able to scroll the listview as normal i.e. vertically and the horizontal scroll view horizontally. Right now i can't scroll the listview but can scroll the horizontal scroll view. Please help me out


Solution

  • use recyclerview to scroll both horizontal and vertical according to your requirement by setting orientation of recyclerview

    to scroll vertical set orientation

     android:orientation="vertical "
    

    and scroll horizontal set orientation

     android:orientation="horizontal"