Comments (8)
I've identified where it needs to be fixed, and why it isn't all that easy to fix.
In the DiscreteScrollLayoutManager
there are two variables, private int childHalfWidth, childHalfHeight;
. These are used in initChildDimensions
to measure and set the values. Various other methods then use these (constant) cached values to perform the LayoutManager logic.
So, what I tried doing was in place of using these fixed ones, I created a hashmap like so private HashMap<Integer, Point> childDimensions;
, and a helper function to measure and cache these values.
private Point getChildDimension(RecyclerView.Recycler recycler, int position) {
if (childDimensions.containsKey(position)) return childDimensions.get(position);
View viewToMeasure = recycler.getViewForPosition(position);
measureChildWithMargins(viewToMeasure, 0, 0);
int childViewWidth = getDecoratedMeasuredWidth(viewToMeasure) / 2;
int childViewHeight = getDecoratedMeasuredHeight(viewToMeasure) / 2;
Point dimension = new Point(childViewWidth, childViewHeight);
childDimensions.put(position, dimension);
return dimension;
}
Sadly, this doesn't work. The offsets are still messed up and the continuous measurements (even though cached) slow down the app greatly.
Since the library developer is more versed in the LayoutManager logic, I'm certain this wouldn't be too difficult a task for them. Highly suggest this is looked into asap!
from discretescrollview.
@yarolegovich any updates ? because this is a very painfull problem I think
from discretescrollview.
Hi @crearo sadly i am so much disapointed with this library .. after wasting whole my day now i saw your issue reported ...now i have very less time to deliver project and i can't even fix ths issue by myself in less time ...do you know any other library with same functionality ,,help would be really apreciated
from discretescrollview.
The main problem here is that we should somehow measure all views and cache their dimensions, and then use the data to calculate scroll distance.
The majority of code which does layout should also be rewritten.
Unfortunately it's very hard for me to find time for these changes.
from discretescrollview.
You can change code like this, which makes the result of the measurement the largest of all Items, but it still doesn't solve the fixed width or height problem.
private void initChildDimensions(RecyclerView.Recycler recycler) {
int itemCount = getItemCount();
int childViewWidth = 0;
int childViewHeight = 0;
View firstView = null;
for (int i = 0; i < itemCount; i++) {
View viewToMeasure = recycler.getViewForPosition(i);
if (i == 0) {
addView(viewToMeasure);
firstView = viewToMeasure;
}
measureChildWithMargins(viewToMeasure, 0, 0);
childViewHeight = Math.max(getDecoratedMeasuredHeight(viewToMeasure), childViewHeight);
childViewWidth = Math.max(getDecoratedMeasuredWidth(viewToMeasure), childViewWidth);
}
childHalfWidth = childViewWidth / 2;
childHalfHeight = childViewHeight / 2;
scrollToChangeCurrent = orientationHelper.getDistanceToChangeCurrent(
childViewWidth,
childViewHeight);
extraLayoutSpace = scrollToChangeCurrent * offscreenItems;
detachAndScrapView(firstView, recycler);
}
from discretescrollview.
@yarolegovich is this issue still not fixed ? It seems that the width and height of all items are stilll dependent on the first item size
from discretescrollview.
@yarolegovich Any updates on this? The library works great. However, not being able to set the height and width of the individual items is a huge turn-off
from discretescrollview.
try to set different holder, and background be transparent. but when horizontal scroll, you only change item's height, and verizontal, you only change item's width. If you want both change w/h, now it's hard.
from discretescrollview.
Related Issues (20)
- ScaleTransformer not transforming uniformly HOT 1
- Make an AsyncTask call in a specific slider HOT 1
- Speed On scroll
- Scroll to Specific Element HOT 2
- ConcurrentModificationException
- How to put the first item on left of screen HOT 1
- If the width of each item is different, it will still use the width of the first item as the default width. HOT 2
- i
- Disable snap to ViewHolder HOT 1
- Fatal Exception: java.lang.IllegalArgumentException
- Library artifacts are published to jcenter only, which will close in 3 months HOT 15
- While using smoothScrollToPosition() the app isn't responding HOT 3
- hello,please What is the reason? HOT 2
- highlight current item with different background color HOT 1
- The view for DiscreteScrollView it will be messed-up after the user lock his phone and unlock it multiple time. please see the attached screenshots. HOT 2
- jcenter error HOT 4
- Rtl LayoutManager HOT 2
- App.getSharedPreferences(java.lang.String, int)' on a null object reference HOT 1
- How to close an infinite loop? HOT 1
- Cannot use with Gradle8 and above HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from discretescrollview.