I need to create large table with horizontal and vertical scrolling. Each cell of this table should be clickable.
To make it clear this is a picture of what I am trying to achieve. Scrollable area on the center, empty cells and cells with numbers should be clickable.
I've tried different approaches, but all end up failed:
GridView
:
Problem: gridview
elements are clickable and scrollable, but scroll is only vertical.HorizontalScrollView
is placed in VerticalScrollView
, while LinearLayout
, which represents a table row, is placed in HorizontalScrollView
. And program built table adds new Linearlayouts
row by row. Scrolling is implemented manually in a parent layout by setting coordinates to scroll views in TouchEvent
. I'm using custom ScrollViews which return false in ontouchevent to set coordinates in parent. Scrolling works fine, but when we attach onClickEvent to a cell(textview), it breaks. Clicking works, but scrolling doesn't. I've tried different modifications (onintercepttouchevent) of this approach, but best result was scroll causing click after scrolling.Also table header should be fixed vertically. The first and last column should be fixed horizontally. I wonder how Google made this in Google Docs app. Their table is perfectly scrollable and clickable.
I found working solutuion. Instead of OnTouchEvent
I use onScrollChanged
and onHorizontalScrollChanged
for manual scroll. With this approach clicking works fine but doesn't work diagonal scroll, because event parameter x is always 0 in onScrollChanged
(and opposite in onHorizontalScrollChanged
).