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.
Related
I want to make a view that looks like a weight scale, like the image below:
For that I thought of using a horizontal scrolling RecyclerView with view holders representing each value of the scale and that works fine, but I can't figure out how to make it curved or if it's possible. I want it to be curved to look more like a weight scale. Does anyone know how I can manage to do that?
I'd say don't go with RecyclerView. It's not intended to be used for such purpose and it might be very time consuming to make it work. I think that the best way is to write a view from scratch. You can draw the scale manually using onDraw(Canvas), simple math and a bunch of drawing operations. The most difficult part would be to add a scroller to get the fling gesture working nicely.
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.
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
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.
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.