How to draw a reverse Z shaped figure using View in Android? - android

I need to draw a reverse Z shaped figure like this in Android using View element. I can't use any image. I need to achieve it using View.
Explanaton of the attached image :
The rectangle box represents the screen of the mobile device.
The reverse Z shaped figure is what I need to draw using View; such that the center of the slanting line ("/") should coincide with the center of the device screen. The other two lines should be of same length as well.
The figure should be relative to the screen sizes.
Thanks!

Create a custom View (a class that extends View)
Call setWillNotDraw(false) in its constructor (to make sure your custom onDraw will be called)
Create custom onLayout method in which you will calculate positions of those four points (store them as fields of your custom View):
Create custom onDraw method in which you will use various Canvas methods to draw your things.
Frame: use drawRect with Paint object that has stroke
"The reverse Z shaped": there many ways to draw this thing e.g. use drawLines to draw lines between points calculated in 3.

Related

How to create two circles of arcs moving by touch in Android

can someone please give me advice or instruction how to create custom view, which draws two circles with different (or maybe same) count of arcs, and the most important, enable rotating each circle independently anti/clockwise by touch move? But no moving on center hole.
I think image describe it best
rotating circles
I needed something like this and I can't find a component so I implement one.
A custom view that uses Canvas in onDraw method .
For each wheel you can add a list of String to show in each section and a list of Paint to paint that section .
https://github.com/mehdi-azizi/Nested-Wheels-View/blob/master/NestedWheelApp/app/src/main/java/com/ma/nestedwheels/NestedWheelsView.java

Android spinning wheel (pizza)

I am trying to create a circle wheel divided in a fixed number of sections. Each section should be clickable.
How I approach this? Should I make an image and set as a background or is there a way to draw all parts in java?
Shortly:
Create .png with pizza.
Create new widget, extending View.
Override onDraw() and draw it to canvas with some rotation. Optionally you can draw lines with java if it's margeritta not a pepperoni.
If necessary - change rotation call invalidate() to redraw view
Add onTouch() listener, get position ot tap, calculate what sector was touched.
One Solution would be to draw different paths for each piece on a Canvas (path.lineTp and path.addCircle - think so). Then you can add ClickListeners to the paths and they will be clickable....

Android - How to create circle view with Android?

I am creating a View as below design here (like apple music).
pic 1:
pic 2:
The pink circle with physical interaction and fly. Can you suggest ways to make them?
Indeed, you should take a look at the custom view documentation.
What you should do to obtain such a result is to first override the onDraw() method in order to make your custom drawing inside.
Using the canvas, you will be able to create circle by calling :
canvas.drawCircle(x, y, radius, paint);
In order to make the circles look as you want, just take a look at the Paint documentation.
You can create as much circle as you want (the app efficiency is, of course, affected by the number of circle you draw).
With your custom view, you will be able to handle interactions easily, through the onTouchEvent() and to animate the circle modifying their properties over time.
You need to write own View as documented here https://developer.android.com/training/custom-views/index.html and then in your onTouchEvent() check if tap is inside or outside of area you consider checkable (in this case inside the given radius).

android - how to define touchable areas inside a circle

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.

Implementing shapes that can be dynamically changed

Am I approaching this correctly or is there a better way?
I would like to have various shapes such as lines, rectangles, etc, that a user would be able to re-size, rotate, and otherwise change its parameters by clicking on the shape and dragging.
So far, I've implemented this with shapes by drawing the shape into a view and then adding the view onto a layout. A user can then drag that view.
But is this the best way? By doing this, I am manipulating the view that contains the shape and not the shape itself.
Can the shape be re-sized/moved directly through user manipulation?
The best way to draw shapes in Android is extend class from view then draw shapes in onDraw method also you can resize and move shapes using onTouch method dynamically.
Refer this link,
http://www.kellbot.com/2009/06/android-hello-circle/

Categories

Resources