Can we use and draw view inside custom view using canvas on Android?
NickName:Clyx Hidden Ask DateTime:2022-11-19T00:50:00

Can we use and draw view inside custom view using canvas on Android?

I would like to know if it possible to use and draw a view such as a TextView or Chronometer inside my custom View which uses the canvas to perform drawing.

My goal is to reuse the Chonometer view from Android inside my custom view and drawing it above all my canvas layers.

I searched like for the whole day, android sources, 3rd party libs but can't figure out.

Also I noticed that on View class there is no way to set bounds or positionning or something so I might not be able to do what I want.

Any help would be greatly appreciated! :)

Thanks.

Something like:

class CustomView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {


    private val chronometer: Chronometer = Chronometer(context)


    override fun onDraw(canvas: Canvas) {
        //Here I perform all my others drawing 


        //Does not work
        chronometer.draw(canvas)
    }


}

Copyright Notice:Content Author:「Clyx Hidden」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74492926/can-we-use-and-draw-view-inside-custom-view-using-canvas-on-android

More about “Can we use and draw view inside custom view using canvas on Android?” related questions

Can we use and draw view inside custom view using canvas on Android?

I would like to know if it possible to use and draw a view such as a TextView or Chronometer inside my custom View which uses the canvas to perform drawing. My goal is to reuse the Chonometer view ...

Show Detail

Canvas does not draw in Custom View

I created a Custom View CircleView like this: public class CircleView extends LinearLayout { Paint paint1; public CircleView(Context context) { super(context); init(); ...

Show Detail

Draw custom view inside custom view

I am working on a custom view, TreeView, which would display a tree given a root node. I am using the Kotlin language. Here's what part of it looks like at the moment: override fun onDraw(canvas:

Show Detail

draw sine wave on canvas inside Image View in android

How I can draw a sine wave on canvas inside an Image View in android, I need it to be draw in the center of the Image View? could you help me please?

Show Detail

Android custom View dimensions and canvas coordinates

I have custom View that should paint a bitmap. I've created a simple line(bmp 1x50 px) to check where will be drawn exactly. In my onDraw(Canvas c) I'm using this line of code: canvas.drawBitmap(b...

Show Detail

Cannot draw on canvas with custom view

I have a class GameActivityas follows (I just post the relevant part): public class GameActivity extends AppCompatActivity { // initiate variables private GameView mGameView; private Display mDis...

Show Detail

Why hardware accelerated View Canvas is slower than SurfaceView Canvas in Android?

As a proof of concept we have built two Android applications which draw 4000 circles on a canvas and move them 1 pixel every frame. The first one, uses a SurfaceView and calls holder.lockCanvas()...

Show Detail

Android -Draw a view on canvas

i have try to draw a finger paint in android using Canvas. I have used the paint for Coloring the Current path.Remove and Appear the paths using undo redo option.But undo Redo works well. i use the...

Show Detail

Custom views inside canvas android

I want to create a GUI in android where I want to achieve the following :- 1) Drag and connect components(image view) to an custom view. 2) While the connection has been achieved the component and...

Show Detail

Use a progressbar inside a custom view?

Hi i have made a custom view and a lifebarprocess.xml . I want to draw the lifebar in my custom view with all the other things i draw. But i don't know how to: -Creat/reference the processbar insi...

Show Detail