I have a custom component that is vertically longer than the screen height and I'm trying to make it scroll. In my onDraw method, I'm drawing the shapes unto a fixed coordinates, and it seems that the content doesn't change even when I scroll. Do I need to draw the shapes unto a different coordinates based on the scrolled position? If so, how do I retrieve the current scroll position?
If you don't want to handle any scrolling from your end, then add your customView to ScrollView. If you want to handle the scroll from your end then you can refer to thebelow link which is for 2Dscroll which handles both Horizontal and Vertical Scrolls.
Android Two-Dimensional ScrollView
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 been puzzled by how to approach this for a while. I have Framelayout with over 20 image views on it. I want to be able to pan the framelayout. Basically, touching and dragging causes the background image to pan (and the 20 image views to move along).
This is similar to what strategy games do (you have map and buildings).
I read all about panning and zooming and they all talking about doing this for single imageview. In my case, not only it is a layout but also it has other views.
How do I approach this? Any pointers ?
Thanks
I have a github project for zooming and panning although its for View Groups it would be easy to change for a View.
Check it out let me know if you have a question it is unfinished but works.
https://github.com/Xjasz/AndroidZoomableViewGroup
Copy the class and extends FrameLayout instead of ListView.
Then make sure in your XML to use the class instead of a FrameLayout.
You could have a TouchInterceptor/Custom view where on touch, you offset the view from its parent by the delta of the current touch coords from the last touch coords.
Problem statement: I would like the canvas to have the same size in both horizontal and vertical orientation. The size should be fixed and based on the vertical orientation (an A4-like canvas). Hence, I need the ability to scroll over the canvas in the horizontal orientation. But there is a conflict between the touch event used for scrolling in a ScrollView and the one used for drawing in the canvas.
What I need: I guess most could settle with this solution: fingerpaint within a horizontalscrollview and simply adding a button for allowing the user to scroll. For me this is a little counter-intuitive. What I would like is to have a thick scrollbar constantly visible on the side of the canvas, like in this app:
Following, this should also be the only way that the user can scroll.
What I have tried: Since the scrollview consumes all the touch events, I have tried overriding the scrollview's onTouch method. But this leads to the whole scrollview being unable to be touched - that includes the scrollbar.
Questions: Is it not possible to implement this with a ScrollView? Do I have to create my own scrollbar widget and align it horizontally (LinearLayout) with the view that contains the canvas? Or is there some way to have the ScrollView only consume touches on the background?
In onTouch override, you can check the coordinates and decide whether the touch was on the scroll thumb or on rest of the view.
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.
I am trying to create a watermark text to my custom view, but the problem is when I scroll the canvas, I am unable to determine the exact co-ordinates of the screen's center.
I tried tracking the onTouchEvent and getting the co-ordinates, but still it is not smooth, it appears on touching the screen during scroll and not always centered.
Is there any way to keep a drawtext out of the scroll?
You can use a framelayout which has to layers. The base one will be the view which scrolls and the top layer will be the textview that has a gravity center. In that case the textview will not be scroll when the base view is scrolled.