Shrinivas Sarmane
Shrinivas Sarmane

Reputation: 1

Tablelayout is not working with ScrollView in Android

I want a horizontal scrollable table but with below code its not working. I have added tableLayout in Linearlayout and then into Scrollview but still its not able to scroll horizontally.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
   android:layout_height="fill_parent" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/ic_main_background_1" >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="horizontal|vertical" >

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

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_sales" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_purchase" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_inventory" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_accounts" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_banking" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_bi" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_budgeting" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_offers" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_reports" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_security" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_staff" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="50dip"
                android:paddingTop="50dip"
                android:src="@drawable/ic_menu_warehouse" />
        </TableRow>
    </TableLayout>
</LinearLayout>

</ScrollView>`

What changes should I do to make it work?

Upvotes: 0

Views: 220

Answers (2)

sandeepmaaram
sandeepmaaram

Reputation: 4241

Just put HorizontalScrollView instead of ScrollView, remaining code no changes. Sample code given below

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent"
android:layout_width="fill_parent">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_main_background_1" >
..........................................................
..........................................................
..........................................................
..........................................................
</LinearLayout>
</HorizontalScrollView>

Upvotes: 1

Scott Barta
Scott Barta

Reputation: 80010

Use HorizontalScrollView instead of ScrollView. According to the docs of ScrollView (http://developer.android.com/reference/android/widget/ScrollView.html), it's vertical-only.

Upvotes: 1

Related Questions