Implementing shapes that can be dynamically changed - android

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/

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 - 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: draw triangle on top of triangle

I am trying to draw something like this http://www.laviny.sk/themes/hzs/images/pocasie/r/r2.png using android XML shape. It is one big triangle (45° on bottom) and one smaller triangle on top of it. I am planing on using it on image like this http://www.laviny.sk/themes/hzs/images/pocasie/r/r0.png. I know that I could use simple png image of this but I want to set its color programatically so thats why I am trying to use android shape.
Is this too complex to be drawn by shape? If not can you please try to guide me a bit because I really dont know how should I approach this problem.
Thanks in forward
Layer-list should be able to do that. The other way is to extend ImageView and draw what you like on a canvas within the onDraw method.

Android: Custom masking 2 bitmaps layered one above the other

easy now.
What I want eventually:
I want to have 2 bitmaps overlayed on a view. Same bitmaps with the one above have higher brightness than the below one.
Now when the user strokes(with touch event (like paint brush)) on the upper bitmap, I want those parts of the upper bitmap to go invisible.
For those who are familiar with adobe photoshop perhaps this will make more sense:
I want to draw a mask on an image being display so that only the unmasked parts remain visible. But the mask can be drawn from a brush with variable hardness/size.
How do I achieve this functionality? Direct me in in the line where I should research or give sample code.
Also, is it possible to draw strokes on an imageview with a brush which has variable hardness? I know that I can drawPath and drawArc on a canvas, but I do not know how to achieve the different brush strokes/styles.
Please pardon me if I haven't phrased my question right, or wasn't able to find similar duplicates.
You can use FrameLayout to overlay one image over other in Android and for Custom Masking search FingerPaint on google.
I think the best way is to do your own off-screen compositing, then render the composited image using an ImageView or perhaps a subclass with custom interaction. See this sample code for an example of how to do such compositing using the Porter-Duff transfer modes.

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.

Categories

Resources