HorizontalScrollView shrinks GridView to small line - android

When I put a HorizontalScrollView around a GridView, the GridView gets compressed into a small column on the left. The Gridview's vertical scrollbar even appears on the left. The HorizontalScrollView's width is set to fill_parent and the GridView is also fill_parent. I don't know why this is happening.
I tried setting the GridView's visibility to GONE and VISIBILE like someone recommended but it doesn't do anything. However if fastScroll is enabled on the GridView, then dragging the fast scroll tab vertically causes the GridView to expand horizontally and it keeps expanding past the last column.

I understand now why this cannot be done. There should be a way to force the GridView to load all horizontal items and allow horizontal scrolling.
The better choice would be for them to implement some kind of DataGrid control. Most people are under the impression that GridView like a DataGrid.

Related

How to make a bi-directional RecyclerView?

I need to be able to make a bi-directional RecyclerView. Basically, it would scroll vertically, but each row would be a horizontal list of tiles that could scroll. The initial scroll position would be at the top and left. The user could scroll down, and scroll to the right with each row.
Any ideas on how to do this? (e.g. with a custom LayoutManager or touch event interception).
I was able to solve the issue using a custom view implementation.
At the root, I have a custom ScrollView; when onMeasure is called, the ScrollView tells its children how tall they should. In this case, they are half the height of the ScrollView. The width matches the height so they display as square tiles.
Each of the ScrollView children are RecyclerView's with a horizontal LinearLayoutManager. Since the ScrollView tells each child how tall to be, there's no issues with measurement and they actually scroll very well in both directions (vertically and horizontally).

How to implement a scrollView with more than one type of grid?

What I need is something like this:
If I use 2 gridViews, they will scroll separately. So I put 2 gridViews into a vertical LinearLayout, both gridViews have fillViewport set to true, and I put this LinearLayout inside a scrollView. But it doesn't work, the scrollView doesn't scroll to the full extent of the 2nd gridView.
I found this: Gridview height gets cut
Looks this can solve my problem by making the gridView grow its height, but as the comments say, this solution is not memory efficient, as it foregoes the cell recycling, and can cause crashes.
Is there any other better way to implement this?
Try ListView with custom items instead. Top grid may be set with setHeaderView method, and bottom grid should be replaced with a set of items to show. This is both default and memory effecient way, it loads only what you show and allows scrolling.

Show Row Per Row While Scrolling Listview -- Android

I have a listview with rows as big as the device screen and I want to show row per row while sliding, I don't want to show parts of rows when doing so, is there any way of doing it.
ListViews are not made for this kind of use case. ViewPagers are, but they scroll horizontally. It's possible to make it scroll vertically (see Android: Vertical ViewPager), which should be what you're looking for.
The problem with adjusting the size of each ListView item to fill the screen is that match_parent simply doesn't work. You would need to calculate the exact size you need (screen height minus action bar and other views that are not part of the ListView). It's probably possible, but not worth the trouble.

How to create two dimensions scrollable table(view) with onclicks

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).

How do I scroll a Gridview in Android, so icons will appear?

I want to scroll the screen vertically in a grid view. As I scroll downwards, icons should appear.
I implemented it in a view flipper which was quite easy. I searched in Google, but couldn't find much help.
If you use android:smoothScrollbar="true" for your Gridview in the layout file, then it becomes scrollable automatically, if the number of grid items exceed the screen size.

Categories

Resources