• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Canvas: why it's null and why it becomes z-higher of another views

QuickNick

Newbie
Jun 27, 2011
32
2
I've created XML-layout and placed in it such views:
1)RelativeLayout with nested SurfaceView.
2)RelativeLayout with rotateable element.

This rotateable element should be over SurfaceView. But when I rotate element (only after that), it becomes hidden under SurfaceView. Also, I tried to fill canvas by transparent (alpha == 0) paint, but with no results.

Also, I tried to draw on the Canvas (I called getHolder() of SurfaceView and then lockCanvas(null) from SurfaceHolder) - but canvas is null.
 
Alternative question: I've tried to draw without SurfaceView, I've created the child of RelativeLayout.
In its constructor I called:
Code:
public CanvasHolder(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layoutInflater.inflate(R.layout.canvas_holder, this);    
        this.draw(new Canvas());
    }
And then override method onDraw():
Code:
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        black.setARGB(255, 0, 0, 0);
        black.setAntiAlias(true);
        int halfWidth = this.getWidth() / 2;
        int height = this.getHeight();
        canvas.drawLine(0, 0, halfWidth, height, black);
    }
No line has been appeared on the view.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones