1

I implement an code to perform Auto HorizontalScrolling using View.scrollTo(...) and postDelay timer to keep scrolling continue.

to start Scrolling I am using :

private void startScrolling() {

        handler.postDelayed(new Runnable() {
            public void run() {

                counter = (int) (counter + 10);
                handler.postDelayed(this, 100);

                    viewCount++;

                    if(viewCount == MAX_CHILD) {
                        viewCount = 0;
                        resetViewPosition(0);
                    }

                    llParent.scrollTo(counter , 0);
            }
        }, 1000L);
    }

At last I remove every first view and add it at again, so simply it goes at last and appear as new child using:

private void resetViewPosition(int viewIndex) {

        View view = llParent.getChildAt(viewIndex);

        Log.v(TAG, "resetViewPosition : "+view.getId()+", "+llParent.getChildCount());
        llParent.removeViewAt(viewIndex);
        llParent.addView(view);
    }

Issue: In this process initially for some of view it function properly but soon next child not visible. Still adding/remove process running and I am getting index id in resetViewPosition(..) properly. It just child view are not drawing.

Please suggest me how can I add and display view while parent view scrolling?

CoDe
  • 11,056
  • 14
  • 90
  • 197
  • So as I see, in the function `resetViewPosition(int viewIndex)`, you're getting the child at position viewIndex, then remove it from the indexed position and finally set the first view at the bottom of the "queue" with `llParent.addView(view);`, BUT, you're calling the function with `resetViewPosition(0);` - thus you've already removed the view and try to go through the process once again. You should change the call to the function with an iterator i = 0%MAXCHILD. – g00dy Jul 26 '13 at 09:16
  • since I already remove index 0 view. So in second iteration, 2nd view will be my 0 index view...this is what i thought? after adding view again I am getting total child count 10, n remove item placing at last index only.I confirmed it using log. – CoDe Jul 26 '13 at 09:25
  • How many child views do you have actually ? What I meant is that the new child is added with the sequentially next index, so you should remove 0,1,2,3 etc. and then re-use your method, but the call to the `resetViewPosition()` is incorrect I think. Try calling it with an iterator, internal counter, which counts how many times the `viewCount = 0;` has been executed. – g00dy Jul 26 '13 at 09:31
  • so when remove o index view, next view automatic become first view...isn't? – CoDe Jul 26 '13 at 09:42
  • I am getting this in log resetViewPosition : 0, 10 resetViewPosition : 1, 10 resetViewPosition : 2, 10 resetViewPosition : 3, 10 resetViewPosition : 4, 10 resetViewPosition : 5, 10 resetViewPosition : 6, 10 resetViewPosition : 7, 10 resetViewPosition : 8, 10 resetViewPosition : 9, 10 so it's confirmed we always deleting 0 index in increment view order. – CoDe Jul 26 '13 at 09:48
  • 1
    Try this out, it could not solve it but will give us valuable info: `View view = llParent.getChildAt(0); attachViewToParent (view, MAX_CHILD+1, llParent); detachViewFromParent (0);` all of this inside `resetViewPosition()`. – g00dy Jul 26 '13 at 11:44
  • Thanks buddy, I did same and it solve my problem certain level. Now my next task to make it circular..and auto scroll..i mention related question here..pls share ur knowledge here http://stackoverflow.com/q/17880250/336990. – CoDe Jul 26 '13 at 12:11
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34229/discussion-between-shubh-and-g00dy) – CoDe Jul 26 '13 at 12:14

1 Answers1

1

As discussed replace this:

private void resetViewPosition(int viewIndex) {

        View view = llParent.getChildAt(viewIndex);

        Log.v(TAG, "resetViewPosition : "+view.getId()+", "+llParent.getChildCount());
        llParent.removeViewAt(viewIndex);
        llParent.addView(view);
    }

with this:

private void resetViewPosition(int viewIndex) {

  View view = llParent.getChildAt(0);
  attachViewToParent (view, MAX_CHILD+1, llParent);
  detachViewFromParent (0);
}

This is some kind of an anomaly, because your method uses getChildAt() and removeViewAt() methods, which apparently leave some empty Views on their ways. I think this could be logged as a ticket.

g00dy
  • 6,752
  • 2
  • 30
  • 43