Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logic behind startScroll in scroller?

I don´t get the idea of startScroll() in this documentation.

It says:

Positive numbers will scroll the content to the left.

I don´t get it. If 0 is always on the left why scroll positive to the left? And if negative it will scroll to the right.

But why? It´s just so hard to wrap my head around it. What´s the logic behind it? Why make positive move to left?

In game and graphics programming 0 will always be either top-left or bot-left but it will always be on the left. So it will make sense to move to right with positive numbers and move to left with negative. But why is it different on startScroll?

I´m just asking cause I´m really curios as to why designed it like this.

like image 892
thenewbie Avatar asked Jul 09 '17 09:07

thenewbie


4 Answers

You are in fact scrolling the view to right, which result the content view to be scrolled to left.

Having |A|B|C|, now scrolling by positive value will result a scroll to right, which scroll the actual content to left: |B|C| - A is not visible anymore, because it is considered as a content and is scrolled to left.

like image 36
azizbekian Avatar answered Oct 31 '22 09:10

azizbekian


To illustrate what is going on, see the drawing:

  • The top drawings show the coordinate system: (0,0) is on the top left, and positive directions are right (x coordinate) and down (y coordinate).
  • The bottom illustrations show the effect of the scroll as it appears as the "view port" is moving.
  • On the left is the position before the call to scroll
  • On the right is the position after the call to scroll by x=+2, y=+3
  • The the light blue rectangle is the screen "view port": the scroll method is actually moving this rectangle (the representation of the screen), and not the content. See it like a camera you look on the world through.
  • The red dot is just an element positioned on the view, and it is not moving. Look at it as the world you look at.

You can see that moving the "view port" in positive x an y directions result on the red dot appear to be moving up and left. Just like you move a camera to the right will make the world in the video move left.

enter image description here

like image 72
Amir Uval Avatar answered Oct 31 '22 11:10

Amir Uval


We can imagine a scroll in two different ways. One is that the window is moving and the other is that the content is moving. According to the Android's documentation of getScrollX()

Return the scrolled left position of this view. This is the left edge of the displayed part of your view. You do not need to draw any pixels farther left, since those are outside of the frame of your view on screen.

it is clear that Android prefers the content respective scroll rather than window respective one. In content respective scrolls

Positive numbers will scroll the content to the left.

Not only startScroll(), other methods like View.scrollBy(), View.scrollTo(), etc. work with the same idea.

If you ask "which is more natural imagination, content respective or window respective?", I will say "I don't know".

like image 1
Durgadass S Avatar answered Oct 31 '22 09:10

Durgadass S


Your Container View is fixed on your screen. When you scroll to right, the right items keeps flowing towards left. Thus, when you do

scroller.startScroll (int 2 /*startX */, 
                int startY, 
                int dx, 
                int dy, 
                int duration); 

makes your content will scroll to the left.

like image 1
Uddhav P. Gautam Avatar answered Oct 31 '22 10:10

Uddhav P. Gautam