How to "scroll" a view of indeterminate size? - android

I have written a custom View which is used to display a tileable pattern, and want the user to be able to zoom in (which I've got covered) and then move around within the pattern.
Because the pattern is tileable it means that there are effectively no bounds on it. In theory a user could just keep scrolling left (right, up, or down) forever. In reality I would be using a modulus to adjust the virtual position.
I'm just not sure where to start. Would I use something with scrollbars? I'm not sure that makes any sense, because as I said the viewable area is effectively infinite.
Thanks for any suggestions!

I'd use a scrollview with the scrollbars turned off.
android:scrollbars="none"

I decided a scrollview was unnecessary. All I really had to do was handle the touch events and then adjust the virtual coordinates accordingly.

Related

how to put elements in fixed positions in a ScrollView

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/

Unclear MotionLayout parameters

Could anyone please explain what MotionLayout's onSwipe parameters touchAnchorId and touchAnchorSide do? This is what documentation says about touchAnchorId
View that is being moved by the swipe.
That doesn't make sense to me as swiping on MotionLayout doesn't move a single view. Swiping progresses transition between starting constraintSet and ending constraintSet. I thought initially that touchAnchorId would specify a view that user will have to drag to progress animation but this isn't a case and MotionLayout developer team introduced touchRegionId parameter for that. It's also unclear to me what touchAnchorSide is supposed to do as I don't see any difference when changing its value.
onSwipe Move progress from 0 to 1 along a
direction(dragDirection=) horizontal (dragRight/Left/StartEnd) or vertical (dragUp/Down)
If I drag my finger a 100 pixels along the screen how much does it move from 0 to 1?
That is the main question most of the other argument answer.
with out an anchor it uses the full length of the layout.
But if you are making a pull out draw that is excessive.
You could adjust it with dragScale. But how much? The pull may vary based on constraints fonts many things.
Many times you want it to act as if you are pulling a view or a side of a view. In which case you ned to the View (touchAnchorId) and the side of the view (touchAnchorSide)
Sometimes you want to limit the region in which the swipe will work
In which case you can use limitBoundsTo.
Much of the rest of the flags are bout what to do when you lift your finger.
There is much more subtly in all the use-cases it is designed to support.

Moving the view's axis for rotation programmatically

I am rotating my View using SetRotationX. However, since this is a scroll view, I want the rotation to always be performed on the visible part of the screen (the middle of it). The default behavior is to rotate it around the middle of the view, which sometimes is out of screen.
I've noticed the "transformPivotX" property, but I'm creating my view on the fly, not from the resources.
Does anyone know how to do it (programmatically)?
Thanks,
yakobom
OK, that was stupid... I dont know how I missed it. It's "SetPivotX"...

Endless horizontally scrolling view to draw content dynamically

I want to create the following view / set of views which behave following way:
I have huge set of points which have been stored to DB in web server.
My client application downloads those and should draw curved lines about the data.
What components should I use here to get this "infinite" scrolling view to draw content dynamically.
No snapping wanted, so it should be smooth and can stop to every X position.
Should I proceed with this by using HorizontalScrollView with horizontal LinearLayout and remove/add views based on scrolling, then translate the scrolling position and provide fling that the scrolling doesn't stop suddenly.
Or is just one canvas possible to use and draw the content to simulate the scrolling?
Maybe a horizontally scrolling ListView component?
The solution should be efficient and use minimum of memory.
Which solution do you recommend, or do you have some new ideas other than above?
All suggestions are highly appreciated. Thanks.
There is several possibilities:
Create custom View class and implement GestureDetector there. You can get movement of finger, calculate currently visible area and draw only visible part of content.
May be this solution is not the easiest to implement, but it will be fast and does not require any resources.

How can I add a Button to a custom scrolling and zooming SurfaceView?

I wanted to add a custom ImageButton on top of my SurfaceView so it essentially scrolls with the View. The canvas scrolls and zooms with a matrix. How could I go about doing this? Thanks.
Assuming I understand the question correctly, can you not just do button.draw(canvas) in your SurfaceView.onDraw() method? You definitely want to bypass the normal layout engine (because it's terribly slow for moving things around) so you'll also have to fake up hit-detection etc.

Categories

Resources