Home > Blockchain >  Android drawLine under view
Android drawLine under view

Time:06-14

In a canvas I draw some lines and place some images, the image is this (image 1)

enter image description here

But I'd like the lines under the images (image 2).

enter image description here

Here the XML for image

<ImageView
        android:id="@ id/image1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical|center_horizontal"
        android:background="@drawable/aw"
        />

Here the XML of the view

<ImageView
            android:id="@ id/i3"
            android:layout_width="45dp"
            android:layout_height="45dp"/>

<view
            android:id="@ id/view"
            
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

in file DrawCoord.kt:

cv.drawColor(Color.TRANSPARENT)
cv.drawLine(....)

In MainActvity.kt:

val p=findViewById<View>(R.id.image1)
val x=findViewById<View>(R.id.i3)
x.setBackground(p.background)

How I can draw the lines under the image?

CodePudding user response:

You can achieve this by changing the z-order of the views. https://developer.android.com/reference/android/view/View.html#setZ(float)

x.setZ(10.0f);

should bring it to the front. Try different (positive or negative) values to see the effect.

CodePudding user response:

Views of the same elevation are drawn in the order you specify in your XML, from top to bottom. The view that you want to be drawn behind the other view should therefore come first in your XML.

  • Related