Android: Fingerpaint with a constantly visible scrollbar - android

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.

Related

Make a scrollview's scrollbar not clickable

I have a scrollview and its vertical scrollbar. If I touch anything within the scrollview and drag, it will scroll the view the opposite direction I dragged. This is the behaviour I need.
If I on the other hand grab the scrollbar and drag it, it will not be in the opposite direction, but in the same direction as I dragged. I could simply hide the scrollbar, but it gives the user a sense of how much content the scrollview contains.
TL;DR
How do I disable touch events on scrollview's scrollbar?

setClipChildren and hardware layers

I have a custom view group that I'm animating around on a screen based on touch events (drag and drop, for instance).
I want it to be able to draw slightly outside its bounds, and still animate smoothly.
I tried setting setLayerType(LAYER_TYPE_HARDWARE, null) on the dragging view, and performance was great, but anything outside the bounds was clipped.
I tried setting LAYER_TYPE_NONE, performance was still fine, but there was animation ghosting/streaking where the view had been dragged (as if it were smearing the screen).
Tried this on a Moto X and Nexus 4, same results.
What's the best way to approach this? Is setClipChildren(false) supposed to work with LAYER_TYPE_HARDWARE? Interestingly, LAYER_TYPE_SOFTWARE exhibits the same unexpected clipping as does LAYER_TYPE_HARDWARE.
Try to use following combination:
setClipChildren(false);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
android:hardwareAccelerated="false"
As described here: ViewPager and setClipChildren(false) workaround for 2.x devices
I had a similar problem when doing exactly the same thing. I wanted a drop shadow beneath my views. The problem is that the system will only clean up the rectangle left by the view you have moved and since you are rendering outside that view by choosing to not clip children, the rectangle is not covering all of your tracks and remains of the rendered view leave a smudgy sort of mess behind.
The solution I used was to put the view I wanted to move inside another view (A RelativeLayout with the child view aligned to the parent's center) that is slightly larger and does cover the drop shadow or whatever else you are rendering outside the bounds of your child. You can set the background of that parent view to transparent/clear. Now attach the drag action to your parent view and the Rect that is cleaned up behind it will also clean up the child's mess.
The only other way I found to do it which was very costly in terms of performance was to re-render the views that show the mess at each frame. I couldn't find any other solutions.

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.

Custom component within scrollview

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

Center fixed text during canvas scroll in Android

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.

Categories

Resources