Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HorizontalListView: scrollTo last items #24

Open
httpdispatch opened this issue Dec 9, 2012 · 13 comments
Open

HorizontalListView: scrollTo last items #24

httpdispatch opened this issue Dec 9, 2012 · 13 comments

Comments

@httpdispatch
Copy link

If i use scrollTo to the one of the last item mMaxX is not calculated properly. This causes problem in scrolling to right (it can't be fully scrolled)

@httpdispatch
Copy link
Author

Current mMaxX forumla is

mMaxX = mCurrentX + rightEdge - getWidth();

But rightEdge can be 0 after all the items removed in removeNonVisibleMethods which gives inaccuracy in calc

Scenario is like this
First list is created and added 8 items. item width is 100.

mCurrentX is 0

Next requested scroll to 10000
removeNonVisible method removes all the childs so the rightEdge passed to fillListRight become 0
When the last item reached mMaxX become calculated. But such as starting rightEdge was 0 mMaxX will be less than necessary on 800 pixels and list will not be scrollable properly on the right side

@httpdispatch
Copy link
Author

Fix proposal. Modify fillList method and use default edge value as mDisplayOffset instead of 0. Currently testing such solution so not sure how proper it is.

        int edge = mDisplayOffset;
        View child = getChildAt(getChildCount() - 1);
        if (child != null) {
            edge = child.getRight();
        }
        fillListRight(edge, dx);

@Dq
Copy link

Dq commented Jan 6, 2013

I'm getting a similar issue, but this fix does not work on my case.

On a 1280px screen I'm drawing 6 items with width 220.
All of them are visible, but when i scroll to the right, since none of the items need to be re-calculated, i'm only able to scroll 40px, which is about the middle of the last item.

Any suggestions on this?

@httpdispatch
Copy link
Author

@Dq do you use scrollTo method?

@httpdispatch
Copy link
Author

@Dq also do you have padding specified on the root layout container for your items?

@Dq
Copy link

Dq commented Jan 7, 2013

@httpdispatch yes, the scrollTo method is being called when I swipe on the list.
Also, the horizontal list view itself does not have padding, but the items have a padding of 15 on left and right sides.
The list work well if I have more or less than 6 item,

@httpdispatch
Copy link
Author

I think this is because of padding. It is used wrongly for offset calculation in one place.

@httpdispatch
Copy link
Author

private void positionItems(final int dx) {
        if(getChildCount() > 0){
            mDisplayOffset += dx;
            int left = mDisplayOffset;
            for(int i=0;i<getChildCount();i++){
                View child = getChildAt(i);
                int childWidth = child.getMeasuredWidth();
                child.layout(left, 0, left + childWidth, child.getMeasuredHeight());
                left += childWidth + child.getPaddingRight();
            }
        }
    }

child.getPaddingRight() seems incorrect here

try to remove padding attribute from the items root and add pading to child

@httpdispatch
Copy link
Author

<root layout>
<child layout padding=15/>
</root layout>

@Dq
Copy link

Dq commented Jan 7, 2013

Assuming is the HorizontalListView, then the items I have inside of it (LinearLayouts) are the ones with the padding. So I think what you're telling me to try is the way it is already (not) working.

@httpdispatch
Copy link
Author

HorizontalListView childs root should not have padding. So if you have layout for child item LinearLayout with padding 15 move that padding from root to child
Layout for child item before

<LinearLayout padding = 15>
   <ChildView/>
</LinearLayout>

after

<LinearLayout>
   <ChildView padding = 15/>
</LinearLayout>

@Dq
Copy link

Dq commented Jan 7, 2013

OK, so that was indeed the issue.
Had to change the padding to the child views.
Thanks!

@michaudhugo
Copy link

I'm getting an issue too with the scrollTo method, but I make no use of paddings.
Sometimes, I can't scroll to the x position that I would like to reach. For example, if I ask for 180 px, it scrolls for an amount of 100px.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants