android - CardView resize animation in RecyclerView - android

I have a RecyclerView with CardView as item in it. CardView has the Arrow icon to show details in the same CardView, but I don't want to set is GONE or VISIBLE because this action has no good looking animation. I tried to set android:animateLayoutChanges="true" on my CardView and I got this: (this is not my screen but it contains the same problem)
But once I click on the arrow again to collapse the supporting text, the card below overlaps the card I've clicked during the animation. How can I avoid this overlapping? I tried to call TransitionManager.beginDelayedTransition(CardView); but looks like it doesn't help me..

You can try removing android:animateLayoutChanges="true" and calling TransitionManager.beginDelayedTransition(MainRootView); (note that call parameter is RootView and not CardView).
If it wouldn't do you should do collapsing-expanging by your own. Here is a good example of view height animating.

Related

Android UI - Efficient to achieve rounded rectangle shape in center with button and text view

Looking for your help. I am using constrain layout. On top of blue rectangle, I have other elements too, but not sure how to achieve the layout that I have shown in the image.
I tried using card view and text view and button inside it. Please let me know if I miss any details or some information is required. Just looking for better approach.
I tried using card view and text view and button inside it
This is fine. And you will need another layout inside CardView because CardView can only hold one child. You can use ConstraintLayout,LinearLayout, RelativeLayout... to hold your TextView and Button.

MotionLayout collapses RecyclerView header but does not expand

I have created a sample project that can reproduce this issue.
Expected Result
When I scroll the bottom RecyclerView upwards, the top RecyclerView collapses
When I scroll the bottom RecyclerView downwards, the top RecyclerView expands
Observed Result
When I scroll the bottom RecyclerView downwards, the top RecyclerView does not expands
Additional information
Try to hold your swipe when the top RecyclerView collapses at the half, and then swipe down. You can see half of the top items being cut.
This only happens for the collapsing View being/includes a RecyclerView.
GIF
(Ignore the changing color - it is just a result of compressing GIF)
Question
Did I do anything wrong or it is a MotionLayout bug?
I came up with an alternative solution.
For easier communication, I will use rvTop for the top RecyclerView and rvBottom for the bottom RecyclerView.
Instead of "shrinking" rvTop, the idea is to "hide" it instead.
So instead of let rvBottom constraint to the bottom of rvTop, we need to introduce a new invisible line in between them, and use MotionLayout to animate this invisible line upwards, while keeping the alpha change of rvTop.
In order to do this, we have to make rvBottom opaque, otherwise it will overlap with the fading rvTop.
I have updated the code in the sample project to demonstrate the changes.
And the effect is:
EDIT:
Another alternative is to remove rvTop's constraint to top of parent after the transition.
Yes, this will make it simply scroll with the rvBottom; but we can add a little bit of translationY to make it "scroll slower than rvBottom".
This can handle the case where you cannot make rvBottom opaque, for example the page itself uses a gradient background.
The effect looks like this:

Image Zoom In and Out with Recycler View Android

I am trying to implement a Recycler View in which the first item covers at-least half of the screen. This item has an image set as a background.
The behavior that i want to achieve is: when user scrolls upward the recycler view, the image should zoom in, and when user scrolls it downward, the image should zoom out and should be in original dimension as soon as the first item is completely visible.
I have tried using setScale() property on imageView but it's not working as expected. Please help!
Keep the first item in CollapsingToolbarLayout instead of placing it in RecyclerView and wrap both the views in CoordinatorLayout.
Then in CollapsingToolbarLayout add parallax effect using attribute collapseMode="parallax"
Finally, bound the RecyclerView scroll behavior to CollapsingToolbarLayout using property layout_behavior="#string/appbar_scrolling_view_behavior".

Drag and Drop view outside of Recyclerview

What I want to achieve: I want to have a view inside a scrollable layout (Recyclerview with GridlayoutManager) with tiles (Views) in it. Dragging and dropping an item inside of the RecyclerView should adjust the position of the icon and swap with the other elements. When a drag starts, an icon above the RecyclerView will change to a trash icon and dragging the view to this icon will delete it from this RecyclerView.
I tried this excellent tutorial, but I didn't find a way how to handle dragging outside of the Recyclerview as the ItemTouchHelper.Callback uses only Recycler.ViewHolder elements as possible targets.
The method interpolateOutOfBoundsScroll() gives feedback if the view moves out of the boundaries, but will only give back the total size that is offscreen, but no coordinates. Also, trying to drag the view out of the Recyclerview always results in cutting of the View where it passes the borders of the Recyclerview.
Does anyone have an idea how I could achieve this effect?
You can achieve this simply by set this attribute for the parent of the RecyclerView:
android:clipChildren="false"
Edit: thank Adam Katz, I don't know why but sometimes you have to add this to the RecyclerView to make it work:
android:clipToPadding="false"
You are bound by the RecyclerView boundries. You have several options:
Make the RecyclerView's layout height to match_parent and to be on top of your upper view (is it a Toolbar?) and add a sticky header of the same size and have an empty transparent layout. That way you could drag ther and see the item floating over there.
Instead of dragging an item to a garbage can icon which is located too close to a legitemate upper-right item, make a long click to select the item (and apply a signal like a check mark or a red mask) and make the garbage can appear and delete uppon click (and maybe allow multi item deleting)

"Glooming" effect layer on the bottom of ListView

Currently, I have an Activity, with a ListView on the top, and LinearLayout on the bottom.
When a row in my ListView is scrolled and the row is partially shown, it looks like this. (LinearLayout is the one with Value wording)
However, I wish to have the following effect.
It seems that LinearLayout adds a "glooming layer" at the bottom of the ListView. - I am sure this is not optical illusion. :)
How I can achieve such an effect?
Add
android:requiresFadingEdge="vertical"
on ListView will solve the problem
One of the ideas that comes in my mind right now is to create a shape with a transparent gradient color. Then create a View above the LinearLayout and put the Shape as the background.
Another idea is to put a transparent image, instead of shape, above LinearLayout.

Categories

Resources