I have in my app a fragment that has 2 Recyclerview - one horizontal and one vertical.
I am trying to implement an "animation" that changes the horizontal RV's views height and width according to my vertical RV's scroll position.
Here is my implementation of NestedScrollView.OnScrollChangeListener() -
featuredProductsNestedScrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener)
(nestedScrollView, scrollX, scrollY, oldScrollX, oldScrollY) -> {
Log.d("scrollYValue", "scrollY - " + scrollY);
Log.d("scrollYValue", "oldScrollY - " + oldScrollY);
// Log.d("scrollYValue", "-----------------");
int calculatedValueFrom = scrollY;
if (scrollY == 0)
calculatedValueFrom = oldScrollY;
else if (oldScrollY == 0)
return;
// if (scrollY > oldScrollY) {
// calculatedValueFrom = scrollY;
// } else {
// calculatedValueFrom = oldScrollY;
// }
// Log.d("scrollYValue", "calculatedValueFrom - " + calculatedValueFrom);
int vendorsRowItemHeight = Math.max(160 - calculatedValueFrom, 80);
// Log.d("scrollYValue", "vendorsRowItemHeight - " + vendorsRowItemHeight);
// Log.d("scrollYValue", "scrollY - " + scrollY);
int newWidth = (int) (303 * (vendorsRowItemHeight / 160f));
int newHeight = vendorsRowItemHeight - 10;
// Log.d("scrollYValue", "newWidth - " + newWidth);
// Log.d("scrollYValue", "newHeight - " + newHeight);
// Log.d("scrollYValue", "-----------------");
int newHeight1 = newHeight * 5;
int newWidth1 = newWidth * 5;
// Log.d("scrollYValue", "newHeight1 - " + newHeight1);
// Log.d("scrollYValue", "-----------------");
// Log.d("scrollYValue", "newWidth1 - " + newWidth1);
// Log.d("scrollYValue", "-----------------");
resizeView(vendorsList, ViewGroup.LayoutParams.MATCH_PARENT, newHeight1);
resizeView(featuredVendorsNestedScrollView, ViewGroup.LayoutParams.MATCH_PARENT, newHeight1);
for (int i = 0; i < currentVendorsList.size(); i++) {
VendorsHolder holder = (VendorsHolder) vendorsList.findViewHolderForAdapterPosition(i);
if (holder != null) {
resizeView(holder.vendorHolderCardview, newWidth1, newHeight1);
vendorsAdapter.notifyDataSetChanged();
}
}
});
private void resizeView(View view, int newWidth, int newHeight) {
try {
Constructor<? extends ViewGroup.LayoutParams> ctor = view.getLayoutParams().getClass().getDeclaredConstructor(int.class, int.class);
view.setLayoutParams(ctor.newInstance(newWidth, newHeight));
} catch (Exception e) {
e.printStackTrace();
}
}
I have some weird behaviour going on in my app when this function works - it does resize the top horizontal RV's views, but for every scroll being made the scrollY value gets rested to 0 so the animation has the feeling of a flickering animation (which is actually not true, it actually does what I wanted but for some reason goes back to the minimal value possible)
here is an image of my log prints of scrollY so you can better understand what I mean -
So basically, for some reason, the scrollY value represents something other than just the value going down...otherwise how can I explain why it resets itself for every time the function is being called?
from Implementing recyclerview holder view size change when scrolling another recyclerview

No comments:
Post a Comment