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).
Related
I have a RecyclerView where each item is a linear layout (orientation vertical) with a text view and another horizontal RecyclerView. The expected behaviour would be that the user would be able to seamless change from vertical to horizontal scroll, but it appears if user tries to swipe horizontally while the vertical scroll is not entirely stopped (yet not visible move, just to swipe fast) or if the horizontal swipe starts somehow from a diagonal motion, the app keeps the vertical scroll and ignores the horizontal one.
Is there a best practice on how to use a vertical recyclerview with horizontal recyclerview items? Tried to search for this a lot, but nothing seems to work.
I want to learn how to solve this problem. I want to have a Horizontal scrollview with the scroll blocked (the user should not be able to scroll it) and inside that horizontal scrollview i want to have another horizontal scroll view, and this scrollview must be able to be scrolled by the user (it haves more content that the width of the screen).
Is it possible to do it?
I tried using this on the parent horizontal scroll view:
((HorizontalScrollView) view).setHorizontalScrollBarEnabled(false);
((HorizontalScrollView) view).setEnabled(false);
((HorizontalScrollView) view).setFocusable(false);
((HorizontalScrollView) view).setFocusableInTouchMode(false);
and this on the child horizontal scroll view:
((HorizontalScrollView) view).requestFocus();
It is not working, the child appears to have a scroll bar, but it cannot be scrolled.
How can this be solved?
PD: I know that this is not a good practice, but I want to learn how to achieve this goal.
You should never use a
HorizontalScrollView with a ListView,
since ListView takes care of its own
scrolling. Most importantly, doing
this defeats all of the important
optimizations in ListView for dealing
with large lists, since it effectively
forces the ListView to display its
entire list of items to fill up the
infinite container supplied by
HorizontalScrollView.
http://developer.android.com/reference/android/widget/HorizontalScrollView.html
UPDATE:
Since you may be forced to use a two dimensional scrollview, you may consider using this:
http://blog.gorges.us/2010/06/android-two-dimensional-scrollview/
I haven't used this but it may be a reasonable approach.
you can do it. But you have to handle child layouts in scrollview i.e ScrollView can host only one direct child.
I have a LinearLayout containing two ImageViews. The LinearLayout is inside the ScrollView.
When I scroll the screen I would like to know the exact position of the two ImageViews relative to scroll. The getScrollY() doesn't work correctly because the ImageViews continues scrolling after action_up and the value in getScrollY isn't updated in this case. I have this information to disable or enable other elements on screen.
If your 2 views are the same/similar then add them to a ListView, then you can set an OnScrollListener which will tell you when the view is scrolled and the index of the visible item.
I was wondering if it was possible to set the scroll range of the android ScrollView. Basically I have a scroll view with one child in it that extends 100 pixels past the bottom of the screen. Normally the scroll view will scroll till it gets to the bottom of the child view, is there a way to get the scroll view to stop scrolling like half way and not show the whole child view? I have tried extending ScrollView and overriding the computeVerticalScrollRange() but that did not work. Any help would be appreciated.
Thanks,
Sam
Do you want it to only sometimes scroll to the bottom? Or never at all? In the case of the latter, I would suggest reconsidering your layout and removing that child from the scrollview parent.
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.