答案 0 :(得分:0)
您可以创建一个自定义视图并在画布上绘制文本。这是一个示例。
自定义视图:
public class TextOverlay : View
{
protected TextOverlay(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
public TextOverlay(Context context) : base(context)
{
}
public TextOverlay(Context context, IAttributeSet attrs) : base(context, attrs)
{
}
public TextOverlay(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
{
}
public TextOverlay(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
{
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
// make the canvas Transparent
canvas.DrawColor(Color.Transparent);
canvas.Translate(100, 150);
var paint = new Paint
{
Color = Color.Blue,
TextSize = 18
};
paint.SetStyle(Paint.Style.Fill);
canvas.Rotate(-45);
canvas.DrawText("CANCELLED", 0, 0, paint);
}
}
将其添加到图像视图顶部的相对布局中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/imageView1"
android:foregroundGravity="center"
android:layout_alignParentStart="false"
android:layout_alignParentTop="false"
android:layout_alignParentRight="false"
android:layout_alignParentLeft="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="false"
android:layout_centerInParent="true" />
<viewoverlay.TextOverlay
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/textOverlay"
android:foregroundGravity="center"
android:layout_alignParentStart="false"
android:layout_alignParentTop="false"
android:layout_alignParentRight="false"
android:layout_alignParentLeft="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="false"
android:layout_centerInParent="true" />
</RelativeLayout>