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.
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.
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.
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".
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.
Scroller is actually the horizontal or vertical side bar, which appear when there is a scrolling gesture. Think about movement in respect to scroller and observe it's behaviour in an app. You will understand why it's implement so. You are currently thinking in respect to touch position, causing the confusion.
Related
I want to create a kind of scroll view that its elements are fixed in the middle of the view and the user needs to move the element a considerable amount or the view bounces back to the middle of the view.
I tried to use several overscrolls next to each other and create a bounce effect but the result wasn't pretty.
is there any library for this kind of scroll view? or there is any way to do this?
If I understand this correctly, you have a fixed element fixed in the middle of the viewport. You want the user to move the element some fixed amount, say X.
If moved less than X, it should go back to the middle of the viewport?
If yes, then you should definitely look into http://bouncejs.com.
Also, this might interest/help you: https://scrollmagic.io/examples/
I have a TextView which I rotate.
The rotation causes the text View to be a little bit translated.
Because of this at the same time I want to do 2 transitions in x and y direction.
I know where the View should be but I don´t know where it is and when one wants to do a translation I only can tell how far I want to transpose not what to.
myTextView.setTranslationX(60);
that is the function I know and every other way you have to give how far not what to.
I always want to translate the view to left corner of my device.
** I know that the first thing that comes to mind is to get the distance between edge of screen and edge of View but that doesn´t work because the rotation hasn´t finished and I can´t wait for it because I want it to look smoothly animated.
I'm using a MultiViewPager with 5 card views inside.
When the card comes from the side to the centre then once it hits the centre a darker shadow appears on the left and right of the card. The pop is really noticeable.
I was wondering if here is a way to gradually update the shadow.
Also if this helps I'm using PageTransformer to move the card up by its Y axis when it gets to the middle.
The question is about com.sothree.slidinguppanel.SlidingUpPanelLayout.
I used the layout with the gravity=top to make the slidingPanel apear at the top of the main context.
But now the slidingPanel does not snap in, when it is moved to the bottom.
It immediately goes returns to the top.
It only snaps in when I drag it a little bit down and then release it.
Seems like the panel has an offset after which it snaps in, which is measured from the bottom.
Event if the slidingPanel is at the top.
Do someone know how to repair that?
The problem with the behaviour I described is with the min. velocity which is required to detect a fling.
Set DEFAULT_MIN_FLING_VELOCITY=0 to make the Sliding Panel expand, after user releases it on any height.
An android WebView and some other views have a nice animation effect of "no more scroll possible" - nice blue filled arc animating with the direction of your finger if you try to scroll after the max scrolling reached. The arc animates as you move the finger and smoothly disappears when you remove/stop the finger. In order to see it, just go to device Settings and try to scroll beyond the maximum.
I'd like to implement the same effect for my HorizontalScrollView.
Please pay attention, it is NOT about fading edge (AFAIK).
Please advise.
Thanks
The HorizontalScrollview should behave like this by default. But what you can try is adding this to your HorizontalScrollview in XML:
android:overScrollMode="always"
or add this to your code:
yourHorizontalScrollview.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
So it will always show the animation left or right depending on the direction you scroll.