I need to draw a tournament bracket in Android. I already calculated the positions for all games (i.e. an (x,y) tuple that defines where to place teams in a spreadsheet-like structure). However, I don't know the preferred way of drawing the bracket. I found an example that shows what I need:Example
My first idea was to programmatically create and fill a TableLayout. However, borders are not really supported and a lot of TextViews are needed to fill the space between games. So I am not sure if this is the best way to do it.
Does anyone have better suggestions or maybe even an example of something similar?
I'd suggest custom drawing using Canvas. That way you can draw wherever it makes sense and probably even support zooming without too much work.
Related
I'm trying to make an app where I can show some statistics.
I have some data that I collect from an STM microcontroller each 5 minutes, and with those data, i want to be able to draw a curve with this data, something like this :
https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQ56Bh-zxV5SZ0OYfaO0sLlxYCuZG0PbDtRR95opMtU80SPDx2r
So, what element in android can allow me to do so and how should i process the data i have ? I thought about using canvas, and making point then drawing the curve using those points, is that a valid method ?
And thanks
You can implement your own CustomView, which allows you to draw, like in a canvas. You can draw lines, curves and charts, but you must implement it manually, by extending and overriding View class method. But it isn't hard. The abilities of the CustomView is wide, you can even use it for simple games. So check this tutorial, if you want to know more.
But if you haven't time for it, you can use libraries, that do all work for you, just like this.
find some components to try in the Graphics section https://android-arsenal.com/free
william chart looks really cool!
I need to make a slider index like this:
(In this case it's indicating that the current index is 3).
Since it doesn't seem to be a finished solution, I have to make a custom one.
2 Possibilites come to my mind:
Create a custom component and draw/update the circles using onDraw. Only "geometric" drawing. But it has limitation in effects. Maybe I want a shiny circle or something, then that will not work. On the other size resize is easy.
Use bitmaps. But I don't know if this is maybe expensive... (If I have 30 or more). And from some count I have to scale down, and this could not look good anymore.
Or maybe something else?
Can anyone advice me what's the way to go to do this...
Thanks.
I am looking to create a custom EditText, where each character entered should lie within its own cell (see image).
My best guess is that I need to create my own .png's for the various states of the EditText, which provide the rectangular outline, then extend EditText's onDraw method to draw the vertical lines that separate adjacent characters.
I've never made a custom view before, and I know little about manual drawing in Android, so some guidance is needed.
Am I on the right path here?
How can I determine how tall and at what location to draw the vertical lines?
What is the best way to eat an oreo?
This is gonna be a very difficult task. Just look at TextView.onDraw() (which you are thinking of override). If I were you, I'd immediately change my mind :)
Instead, I'd use a LinearLayout to hold an array of customized EditText, but I don't know what kind of interaction you are looking for
Finally, to measure text you use Paint.getTextBounds(). Where to draw vertical separators depends on your design. If you have a fixed number of fixed length cells, you know where, otherwise you need to measure text
the question "What is a usefull alternative to AbsoluteLayout?" seems to be a question which is often asked, but never really answered. My situation is as follows:
I want to position Circles (for the sake of simplicity i used RadioButtons for testing) so that the distances between the circles are proportional on all possible display sizes.
Also i need to know the position of the circles to match onTouchEvent.
This seems fairly easy with AbsoluteLayout since i can get (at runtime) the defaultDisplay's width and height and so i can position Objects in an AbsoluteLayout relative to the display metrics.
Now I want to avoid AbsoluteLayout for obvious reasons, but RelativeLayout doesn't seem to be an alternative since - as far as i know - one can only say "put that object right next to that other object" or below or whatever. How to fix this?
In my Opinion the best way to achieve your goal is to use the Canvas and draw everything yourself. In the Canvas you have the information of the screen at runtime and you have full control of the things to draw.
If you only need to draw your own shapes (and handle all normal touch events) and do not need other UI Widgets on the same view, then use Canvas.
If you do need Widgets on this view then your only option is AbsoluteLayout.
I'm fairly new to the Android platform and was wondering if I could get some advice for my current head scratcher:
I'm making an app which in one view will need an image, which can be scrolled on one axis, with a load of selectable points over the top of it. Each point needs to be positionable on the x and y (unlikely to change once the app is running, but I'll need to fine tune the positions whilst I'm developing it).
I'd like to be able to let the user select each point and have a graphic drawn on the point the user has selected or just draw a graphic on one/more points without user intervention.
I though for the selectable points I could extend the checkbox with a custom image for the selected state - does that sounds right, or is there a better way of doing this? Is there any thing I can read up on doing this, I can't seem to find anything on the net about replacing the default images?
I was going to use the absolute layout, but see that it's been depreciated and I can't find anything to replace it.
Can anyone give me some code or advice on where to read up on what I need to do?
Thank you in advance
This really feels like something you should be doing with the Canvas and 2D graphics, rather than trying to twist the widget framework to fit.