I am trying to make a horizontally scrolling grid. It has two rows. The second row is offset (by half the width of one item, but that is trivial to calculate and doesn't matter here).
I am currently using RecyclerView and the GridLayoutManager from https://github.com/antoniolg/RecyclerViewExtensions/tree/master/library/src/main/java/com/antonioleiva/recyclerviewextensions
However, the offsetting is proving extremely difficult.
It should end up looking like
Does anybody have any suggestions for making the second row staggered like in the picture above?
Use StaggeredGridLayoutManager with an ItemDecoration which adds the offset to the item at adapter position 0. You'll get the desired output. (via getItemOffsets).
Alternatively, instead of an ItemDecoration, when onBind is called, you can set the first item's width such that it will include gap on left.
If your data set changes, don't call notifyDataSetChanged which will reset the historical calculations in SGLM. Instead, use detailed notify events like notifyItemRangeInserted so that SGLM will be able to recalculate layout without resetting positions.
I don't know if you're still working on this, but my approach would be to render the items 2 at a time (top/bottom) with the appropriate offset, and then play with your horizontal margins (set them to negative) to create the overlap between item 2 and 3, etc.
You would have to tie OnTouchListeners to the individual items being rendered, not the RecyclerView entries.
Related
I have Horizontal cyclic ReacycleView. but I want in recycle view's middle item(ImageView) height be greater as compared to other side items.
Recycle view items
That means if any item in the center of RecycleView, it's height should be greater in RecycleView itself.
You can use a different layout for your middle item by implementing getItemViewtype() in your adapter. Similar question and answer here should point you in the right direction.
I created a sample app with this functionality and here is code.
Let me know if you need some explanation.
You need to create A custom layout manager and Item Transformer
CenterLayoutManager
Repository
ScaleTransformer
Hi I need to implement the layout as attached in pic. I have tried this StackOverFlow answer
but the resultant view get created as attached below
I need that bottom right corner to be above next cell of recyclerview.
Please suggest how can make top of the cell below previous cell.
It looks like you're close. The problems you're seeing here are:
The offset you're using in the item decorator from the example you used isn't large enough - hence the black gaps
The order in which your linear layout manager is stacking your views is from the top, which means that the row below will draw over the cell above.
To fix this, first, add a bit more offset to get rid of the black gaps.
Second, call setReverseLayout(true) on your LinearLayoutManager (can also be done via the constructor) - this will make it draw the bottom items first, so that the cells will draw above the cells below.
Also, you might want to play around with the elevation of the views to get that neat shadow effect, making sure that a row at index N will have a higher elevation than a row at index N+1. You could do this by calling myView.setElevation((getItemCount() - position) * SOME_DP_AMOUNT) when binding each view in your adapter.
I'm trying to make the items within a RecyclerView scroll along a path, specifically a curve. At the left and right edge of the screen the offset is 0, and in the middle of the screen the offset is 100% for example. I am attempting to achieve this by setting the Y translation of each view. Currently I am doing this in an OnScrollListener attached to the RecyclerView. This mostly works OK, but there are occasions where the OnScrollListener isn't invoked so the translation resets to 0. These occasions include when adding or removing an item from the RecyclerViews adapter.
Is there a better place to attempt to achieve this effect? I have also looked into using my own LayoutManager and overriding OnLayoutChildren, but again this doesn't work in all cases and isn't called when scrolling.
I've been trying to work out how to calculate the y-position of scrolled content inside an Android ListView. The consensus seems to be that Android simply doesn't give you this information and you have to work it out by doing all sorts of calculations based on the getChildAt(0).top and getFirstVisiblePosition() methods.
My question is to try to understand why Android doesn't give you this information. It would seem to that the the list view must actually know this value somehow in order to draw the scrollbars. Or at least know it as a percentage? The ViewPager's onPageScrolled() method seems to do the same thing. And it's a trivial matter in iOS as well.
ListView is not same as ScrollView as you thought of.
For example, if you have 10 items with use 2048px hight. If you wrap them in scroll view, the inside content is 2048px height. However, in ListView, the 10 items will be populated dynamically. It is always in the displaying area, thus the scrollY = 0.
If you really want to calculate the ScrollY of ListView, you might need to take care of it by yourself. You can getFirstVisiblePosition() to get the index of the current top visible item. And consider the height of each list item and list divider, you might be able to get the total scrollY value.
I have a ScrollView->TableLayout->TableRow
Inside the TableLayout thare are some TableRows visible and some gone. Its because clicking a TableRow, some other rows below it will become VISIBLE.
Its everything ok now, except that the rows that I turned VISIBLE may not appear in the screen because they arent in the scrollview display area.
I wanna display them without the user scroll, so I need to get the row position to do the scroll.
The problem is, the Draw inst immediately, so I cant get the position. I tryed invalidate and postinvalidate but inst working.
What should I do?
EDIT: What I realy want is a way to update positions and sizes of my views.
I found the solution here (Android) Why won't invalidate() update my buttons immediately?
Do you know where the newly-visible cells are going to be drawn? If you have, say, the cell immediately above it (which would make sense if you're adding the rows with addView()), you can get the bottom position of the cells immediately above your newly-visible cells (with getChildAt() then calculating the vertical offset), and then use scrollTo() (or the sexier smoothScrollTo()) to scroll to that position - that should scroll so that the new row is at the top of the screen. Highlighting the new row somehow would also help the user see that this is the new content.
if you can calculate the rowHeight. or the height of each row. then you may be able to calculate the position where the row (view) may appear.
and you can call the
scrollView.scrollBy(x, y)
or
scrollView.scrollTo(x, y)
in the scroll view.