How can I have RecyclerView children ignore relative positioning? - android

I am experimenting with a RecyclerView and it currently displays four CardViews vertically on the screen. Using an adapter, I am able to resize each CardView's height equally in the space given.
What I'm trying to accomplish:
On click, I would like the selected RecyclerView child to expand to fullscreen. Currently, I can programmatically set the height and expand the selected CardView dimensions, but the other CardViews after it are pushed down off-screen. How can I have all the selected CardView positioning become absolute, and lock the other views positions and expand "over" them? Is this the proper approach, or should I be looking into shared-element transitions or something else?
Side-ask: Is there a way to control all top/left positioning of RecyclerView children in an adapter?

The comments above seem to be correct - after looking into shared transitions, I found numerous examples performing the exact behavior I described. Crediting #AmratSingh since he answered first.
If it helps anyone, here is the one I am following currently: Michael Scammell - Shared Element Transitions
This one in particular: Shared element transitions within a RecyclerView

Related

Why RecyclerView items disappear immediately when using Transition API?

This is a question regarding the use of Android Transition API.
I am trying to animate the height change of a list, just like a dropdown menu.
I tried 2 approaches
Use a RecyclerView and animates its height change
Use a ScrollView > LinearLayout hierarchy and animates ScrollView's height.
The 2nd approach works perfectly.
But the 1st approach has a serious glitch - when the collapse transition starts, items disappear immediately.
By looking at the below GIF you can observe clearly the difference:
To be exact, items' visibility changes at the moment I change RecyclerView's LayoutParams, without waiting for the transition to finish, whatever it is expanding or collapsing
Code
I have created a minimal project on Github.
If you just want to look at the code, here is the MainActivity.
Question
Is it possible to achieve ScrollView's effect with a RecyclerView?
If yes, how?
My Idea is to do the transition of all the recycler view rows individual rather than the whole RecyclerView:
So when collapsing iterate through each ROW of a RecyclerView and do a transition. Remember to check for null if some rows are recycled they may return null. So after that collapse the whole recyclerView.
And like wise for the expanding do the same for the views.
This issue is cause by RecyclerView has many views with it but Scroll View has only one View nested in it.

Multiple non-scrollable lists in a ScrollView in Android

I am trying to put multiple lists that don't need to be scrollable inside a ScrollView. In other words, I have a TextView as a header for a category, with a list under it. Then another TextView as another header, with another list under that. And so on. This is in a vertical LinearLayout.
I want to be able to scroll through this layout as it gets off the screen when it has too much info, but I want all the contents of the lists to be displayed.
I've tried putting the headers (the TextViews) and the lists inside a vertical LinearLayout, and that LinearLayout inside a ScrollView. The problem with that approach is - all the lists have a max vertical dimension of exactly one element (if I set them to "wrap content"), despite the lists having multiple elements. Believe it or not, the lists do scroll (and they're inside of a ScrollView, more exactly, inside of a ScrollView -> LinearLayout).
If I remove the ScrollView, then the lists do indeed appear with all their elements, but I can't scroll the view if it goes off the screen.
So, if I use a ScrollView, I only get one element per each list. If I don't use it, I get all the elements of the lists correctly, but it doesn't scroll.
Any ideas of solving this? Thanks!
Nevermind, eventually found the answer here and it works perfectly:
https://stackoverflow.com/a/27818748/5627584
This ^^^ is a very underrated answer as I have hardly found it, but it's very, very useful when trying to include lists inside of superior layout node that has to be scrollable (inside of a ScrollView -> LinearLayout that contains other interface elements).

How can I create an horizontal ListView in Android with fixed number of items?

I searched for a few hours over the internet but I didn't find any example or documentation explaining how to create an horizontal list view with fixed number of elements.
Basically, I would like to have, let's say 3 elements out of n(total number of elements) which are displayed on the screen without taking into consideration the size of the scree. The elements can be bigger or smaller proportionate to the screen but the number of visible elements should be the same, fixed. see the image.
How can I do that? Any hint is appreciated! Thank you!
You can use TwoWayWiew third party library (i dont really recommend this solution), or if you want to avoid to use lib for this, just use RecyclerView, and you can set HORIZONTAL param to layout manager.
I would not use a ListView for this, but a RecyclerView instead. Performance is better in a RecyclerView and I honestly find them easier to work with. You can allow for horizonatal scrolling via the LayoutManager for your RecyclerView.
If don't mind scrolling horizontally by 3 items you could use a ViewPager with each View containing a LinearLayout (orientation horizontal) with three of your elements that have a
android:layout_width="0dp" and an
andriod:layout_weight="1"
for even distribution.
When you "scroll" you would just animate the next "page" into the screen bringing in the next 3 elements.
This might not be the most elegant solution but I think it would behave the way you want.
use the linear layout with its orientation set as horizontal under the relative layout

Enlarge (pop) element in grid, not pushing the other Views

I would like to know if there is an easy way of having a grid of elements, where when one of the elements is pressed,
This state:
Changes, to reveal the touched element (center element here)
For a start, I thought manually re-adding the element as over all others, then programmatically setting the position to keep it appear to be centered.
Is there an easier way, or do I have to break a bit of sweat for it?
As far as I know, Android animations don't affect views boundaries. Therefore, you could simply use setScale method of view to scale them up and down. Also, you could considering animations for better UX.
In Android there are two general way for displaying a grid of views:
Grid View
Grid Layout
In both approaches, this trick can be used.
For each cell (individual views) add a touch listener in which whenever the touch is of type down, scale it up and otherwise scale it to normal.
In Grid Views, you should do this in its adapter while for a grid layout you could iterate over its children and apply this.

Android ViewPager set current element always on center

I need a vertical ViewPager that has selected view always on center.
Something like Android's gallery widget works (selected element is always in center).
I have tried to implement vertical Gallery, but since it's deprecated...I would like to have this functionality via ViewPager.
Is there a way to manage that selected view is always on the center?
Also how to manage scroll amount of ViewPager?
For example...when I scroll trough the content I want to scroll for exactly one element's height.
Also I need mechanism how to define exact amouth of pixels for scrolling list view.
When list scroll I don't want it to only show next item, but to scroll for exact amount of pixels to always show the part of the following item.
Tnx for your help!
Im not sure if i understund the question. Isn't it as easy as this?
viewPager.setCurrentItem(viewager.getAdapter().getCount()/2)
About scrolling the pager to an specific amount of pixels,
You have to signal the ViewPager by calling beginFakeDrag() and endFakeDrag() on it. After starting a fake drag you can use fakeDragBy(float) to drag the ViewPager by the given amount of pixels

Categories

Resources