I'm a bit confused how Drawable, View and Surfaces should be used in Android. Imagine the following scenario: One main view that can be zoomed (pinch zoom) and on which the user can tab at any point. Everywhere the user tabs I want to add a pre-defined shape and connect all of them by a line.
So I need a zoomable main view which I draw myself in onDraw() method. Then I need to define my drawable in a XML file that will visualize my tab-position and draw that on each of the tabbed position in the view?
I would be glad if you can point me into the right direction how to realize the above scenario the right way.
Related
I want to create a shape like this image.
I searched a lot for drawing on canvas with different shapes.
I didn't got anything on StackOverflow or Google.
Here is the link I referred
In this tutorial I got to know how to use the curves with canvas.quadTo();
Android How to draw a smooth line following your finger
How to draw a curve according to a control points list that has more than 3 points
//here i got to know about canvas.cubicTo() method which will give curves from start point to end point with middle point.
I don't have any code to show, so, I need to start from scratch.
I need this to be created as ViewGroup, so that I can add 1 View to this ViewGroup. If I add another View into this ViewGroup then the background should look like this.
Once again I started to experiment with Android things. I'm trying to create a small simple game, which uses a hexagonal board. I know the math behind the hexagonal calculations, but the problem is how to actually implement such board in Android?
At first I thought of using a grid view where every other line is displaced by half step and then use these square grids as my board and just draw a hexagonal shape over the square boxes. However, the regular grid view doesn't seem to allow me to do that.
So I thought that maybe I need to create a custom view with either hexagonal grid or a custom view with square displaced grid.
I'm not familiar with Android custom views. I read a tutorial about custom views from Vogella's tutorials but I'm still very unsure, if it's even possible to create a hexagonal grid as a custom view.
So any ideas and help of how to create and implement a hexagonal game board on android?
I would certainly go with a custom view for this. When you draw the view, you can have a loop that draws each hexagonal tile in the right place within the view as a whole. This will give you the most flexibility.
I suggest you start by writing a method that determines, for any given point within the whole view, which hexagonal tile it's in. You'll need this for determining which tile was touched, and it will also help with the drawing.
The nice thing about it is that if you keep track of the centre of each tile, then for any given point, the nearest centre point will tell you which tile the point is located in.
How can I draw (bitmap, line, etc) outside the bounds of a view? From the view's onDraw(), I've read this is not possible as everything drawn will get clipped to the view's bounds.
I did come up with one solution but I'm hoping there's a better one. What does work is to create a transparent view that is at the top of the z order and includes the area I want to draw in (the entire app client area). Then, whenever I want to draw outside some child view, I can simply translate to the coordinates to the transparent view and draw there.
I also read about SurfaceView hoping that would do what I want. But I think it's main purpose is to provide drawing in a separate thread and doesn't solve the problem I'm discussing.
To be clear, it isn't sufficient to simply draw in the parent of the target view because other views in the parent will be higher in the z order and hide the drawing.
Intuition tells me there's a "right way" to do this. Anyone know?
I'm drawing the conclusion that the right way is to do what I proposed - create a transparent view that is at the top of the z-order for the space you need to draw in.
I come to this conclusion after learning how the Navigation Drawer drawing works - exactly in this way. So, if Google uses this technique, I conclude that it's the best way available.
I am always confused about this and I need a pointer on how you would do it. If create a an xml layout with multiple imagesview and text view. And Lets say I want to draw line between two images and move an image along this line. How do I draw this line? I know I can get location of both images view so I have x1,y1 and x2,y2. My problem is with drawing.
Do I need surface view to have the drawing capabilities and loading bitmaps on the screen along the line?
If yes, then I guess I should always surface view to fill the screen and views on top just incase I need to draw which seems kinda wrong?
IF no (I hope thats the answer), then how do I draw lines, or load bitmaps on screen using only X,Y values?
I hope I was able to explain my confusion
Thanks
EDIT: Actually I thougth of a way of explaining my confusion better.
When you create an activity with xml layout you have something like
onCreate (){
setContentView(R.id.layout)
}
but when you have activity with drawing view you have something like
onCreate (){
SurfaceView v = new Surfaceview(this);
setContentView(v)
}
My problem is that we have to set the content layout to EITHER xml layout or to be drawing area . What if I want to set it to my xml layout and at the same time I can draw anywhere on the screen (over images view, empty areas, TextViews ..etc)
See my question?
That depends on what your desired result is and how much flexibility you need. You can have a look at this android Animations tutorial (the site is down at the time of posting but google has it cached).
If you don't need flexibility, then for your line, you might be able to create a View in your xml with an android:background fill color and a size that makes it look as you wish. You could then use an Animation on your bitmap's ImageView to translate it along the line, and use a listener on said Animation to show/hide the various Views as necessary at the beginning or end of your Animation.
If you need flexibility, the SurfaceView is probably your best bet.
I'm currently trying to create a circle (via canvas drawing, opengl or drawable) and define 4-5 buttons inside of it. My first thought was to create some drawables (quarters of circles) and overlay them onto the main circle, but then I'll have the touchable zone too large - e.g. in the middle of the main circle.
Is there anyone who tried this and found a decent solution to it?
You could just override onTouch() in your custom View that draws the circle (and other button graphics), and do a bit of simple maths when you get the finger down event to determine whether the user has touched within the circle, and what particular defined zone within the circle.