androidandroid-scrollviewhorizontalscrollview

HorizontalScrollView doesn't scroll


I want to make a Table with a solid column on the left and scrollable columns on the right that scoll horizontally. I've devided it into two differnt Table Layouts and put the right one in a HorizontalScollView. Later on I'll add all of these columns dynamically. The problem im facing is that the ScrollView somehow doesn't scroll. It peaks out of the screen like it should but on the emulator and my phone it doesn't move at all.

I implemented it like this:

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

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp">
        <TableLayout
            android:id="@+id/TL_halteStellen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:background="@drawable/table_border">

            <TableRow>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="30sp"
                    android:text="Haltestellen "
                    android:background="@drawable/tv_haltestelle"/>

            </TableRow>

            <TableRow>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="30sp"
                    android:text="Borken"
                    android:background="@drawable/tv_haltestelle"/>
            </TableRow>


        </TableLayout>

            <HorizontalScrollView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintLeft_toRightOf="@id/TL_halteStellen"
                app:layout_constraintTop_toTopOf="parent"
                android:orientation="horizontal">

                <TableLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/table_border">

                    <TableRow>
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:paddingHorizontal="6dp"
                            android:text="06:35"
                            android:textSize="30sp"
                            android:background="@drawable/tv_haltestelle"/>
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:paddingHorizontal="6dp"
                            android:text="06:35"
                            android:textSize="30sp"
                            android:background="@drawable/tv_haltestelle"/>
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:paddingHorizontal="6dp"
                            android:text="06:35"
                            android:textSize="30sp"
                            android:background="@drawable/tv_haltestelle"/>
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:paddingHorizontal="6dp"
                            android:text="06:35"
                            android:textSize="30sp"
                            android:background="@drawable/tv_haltestelle"/>
                    </TableRow>
                </TableLayout>
            </HorizontalScrollView>
    </androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>

How can I fix it or is there a better way to implement this design?

I tried everything that I could find online and rewrote it serveral times


Solution

  • Here are some things to try if a HorizontalScrollView isn't scrolling: Recreate the structure elements: Recreate the structure elements down to the root canvas. Add a transparent panel: Add a transparent panel on top of the HorizontalScrollview. Add left and right margins: Add left and right margins to the LinearLayout with the ID group_container.