Использовать Framelayout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/iamge_text_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:orientation="vertical"
android:padding="6dp">
<ImageView
android:id="@+id/imageview"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:contentDescription="@string/image"
android:src="@drawable/image_background" />
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Drawing ,Text over images"
android:textColor="@color/white" />
</FrameLayout>
Создать пользовательский вид и переопределить ваш холст
@SuppressLint("AppCompatCustomView")
public class CustomView extends ImageView {
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float left = getPaddingLeft();
float top = getPaddingTop();
float right = getPaddingLeft() + getWidth();
float bottom = getPaddingTop() + getHeight();
float centerX = (left + right) / 4f;
float centerY = (top + bottom) / 2f;
Paint pText = new Paint();
pText.setColor(Color.RED);
pText.setTextSize(50);
canvas.drawText("Drawing Text over images", centerX, centerY,
pText);
}
}
Добавить этот пользовательский вид в xml
Снимок экрана