Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Diagonal Scroll Vertical + Horizontal Scroll View ->Table Layout

Tags:

android

I implemented a table layout inside a Horizontal scroll view which is again child of vertical scroll view. It works like this; When scrolling vertically or Horizontally it scrolls explicitly for each scroll type. Means while scrolling vertically horizontal scrolling does not happen at all, say if finger moves diagonally no vertical or horizontal scrolling occurs . To Scroll it horizontally it has to be touched again and it scrolls only in horizontal direction, if finger moves diagonally no vertical or horizontal scrolling occurs .[Same case here].

Seems like only one callback is handled at one instance of finger touch. I need diagonal scrolling too, should scroll simultaneously vertically and horizontally, like in iOS Table View. scrolls in all 6 directions.

Here's Code;

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <ScrollView
            android:id="@+id/layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="5dip"
            android:scrollbars="none">

            <HorizontalScrollView
                android:id="@+id/horizontalView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip"
                android:scrollbars="horizontal|vertical">

                <TableLayout
                    android:id="@+id/tlGridTable"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TableRow
                        android:id="@+id/row1"
                        android:layout_width="wrap_content"
                        android:layout_height="50dp">

                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                    </TableRow>
                    <TableRow
                        android:id="@+id/row1"
                        android:layout_width="wrap_content"
                        android:layout_height="50dp">

                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                    </TableRow>
                    <TableRow
                        android:id="@+id/row1"
                        android:layout_width="wrap_content"
                        android:layout_height="50dp">

                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                    </TableRow>
                   ---------------
----------------------
--------------------------
                    <TableRow
                        android:id="@+id/row1"
                        android:layout_width="wrap_content"
                        android:layout_height="50dp">

                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                    </TableRow>


                </TableLayout>
            </HorizontalScrollView>
        </ScrollView>
    </LinearLayout>
like image 367
Jayant Arora Avatar asked Feb 10 '15 10:02

Jayant Arora


1 Answers

I found the answer on this Link: Probably the Same Question.

Scrollview vertical and horizontal in android

   @Override
    public boolean onTouchEvent(MotionEvent event) {
        float curX, curY;

        switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                mx = event.getX();
                my = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = event.getX();
                curY = event.getY();
                vScroll.scrollBy((int) (mx - curX), (int) (my - curY));
                hScroll.scrollBy((int) (mx - curX), (int) (my - curY));
                mx = curX;
                my = curY;
                break;
            case MotionEvent.ACTION_UP:
                curX = event.getX();
                curY = event.getY();
                vScroll.scrollBy((int) (mx - curX), (int) (my - curY));
                hScroll.scrollBy((int) (mx - curX), (int) (my - curY));
                break;
        }

        return true;
    }
like image 148
Jayant Arora Avatar answered Nov 07 '22 10:11

Jayant Arora