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.
Related
In this above picture, all circle is a view with three text view. These views will be added dynamically. It will be 4 to 15
And at the below circle view with three text view will be fixed.
All circle will be connected with the end one. and will need to draw a line with one another. And at the middle of the line there will also be a textview.
How to implement this custom view. Any kind of will be appreciated.
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 wish to draw endless board like game world map of endless cell grid. User will be able to scroll it, but the data will be stored in memory, not on scree. I.e. I will populate cells when they are appear on screen and delete them on hide.
How to implement this in Android?
In javascript and java I would use 2 nested absolute panes or divs with no clipping.
You can do the same thing with a RelativeLayout by changing the view's left and top margin as if it was the x and y coordinate.
The best way is to override onDraw(Canvas canvas) method of View sub-class and paint the area you want to display. Put your game character in the center and redraw the View with invalidate().
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 an image of a map that I have placed inside a WebView to enable zoom and scrolling. This works fine.
I know the latitude/longitude of the top-left and bottom-right corners so I can calculate positions on the map.
The problem is that I want to place a series of clickable points on the map at specific positions. I have got some success with setting the view padding and then using webview.addView(pointView). The problem with this is that the padded area is made clickable as well, sometimes overriding other points. Setting a layout margin does not seem to work at all (clickable view is placed at top-left corner).
Anyone know how to solve this?