How to make a scrollable TableLayout?

AndroidScrollAndroid Tablelayout

Android Problem Overview


Look at the XML code here please:

<TableLayout
	android:id="@+id/tableLayout1"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:padding="10dip"
    xmlns:android="http://schemas.android.com/apk/res/android">
    
    <TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <!-- Some stuff goes here -->

    />
    </TableRow>

    <TableRow
    android:id="@+id/tableRow2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <!-- Some stuff goes here -->

    />
    </TableRow>

    <TableRow
    android:id="@+id/tableRow3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <!-- Some stuff goes here -->

    />
    </TableRow>
    

</TableLayout>

My code is much longer than that but I just eliminated the unnecessary parts. The problem is I want to make this TableLayout a scrollable so that all of my stuff can be shown.

I tried to put this line in the TableLayout in order to make it scrollable:

android:isScrollContainer="true"

But it does NOT do the job. Is there a way ?

Android Solutions


Solution 1 - Android

Encase the whole thing in:

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
    android:layout_weight="1">
    <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical">

    ...

</ScrollView>

Solution 2 - Android

You don't technically need the LinearLayout in the ScrollView:

<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_weight="1">

    <TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    android:isScrollContainer="true">

    <TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

        <--!Everything Else You Already Have-->

    </TableRow>
 </TableLayout>
</ScrollView>

Once you take up enough room within the ScrollView, the scrolling effect will activate (kind of like an HTML TextArea, once you have enough lines of text, the scrolling activates.)

You can also nest the ScrollView, but again you cannot feel the scrolling effect until you have enough content in the ScrollView.

Solution 3 - Android

thanks mbauer it's solved my problem i place in order

  1. TableLayout
  2. TableRow with end (for the header of columns)
  3. ScrollView
  4. LinearLayout
  5. x TableRow with end
  6. end LinearLayout
  7. end ScrollView
  8. end TableLayout

Solution 4 - Android

It works too inside Constraint Layout. Just add the following attributes on your TabLayout.

<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TableLayout
            android:id="@+id/tableLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:isScrollContainer="true">

        . . .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioniTurkiView Question on Stackoverflow
Solution 1 - Androidcitizen connView Answer on Stackoverflow
Solution 2 - AndroidArtorias2718View Answer on Stackoverflow
Solution 3 - AndroidPhilView Answer on Stackoverflow
Solution 4 - AndroidNakamotoView Answer on Stackoverflow