有一个类继承自 TextView
using Android.App;
using Android.Content;
using Android.Content.Res;
using Android.Runtime;
using Android.Text;
using Android.Util;
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using Android.OS;
using Android.Graphics;
namespace HelloWorld
{
class TodoListItemView:TextView
{
private Paint marginPaint;
private Paint linePaint;
private int paperColor;
private float margin;
public TodoListItemView(Context context, IAttributeSet attrs, int ds): base (context, attrs, ds)
{
init();
}
public TodoListItemView(Context context, IAttributeSet attrs) : base(context, attrs)
{
init();
}
private void init()
{
Resources myResources = Resources;
marginPaint = new Paint(PaintFlags.AntiAlias);
marginPaint.Color = myResources.GetColor(Resource.Color.notepad_margin);
linePaint = new Paint(PaintFlags.AntiAlias);
linePaint.Color = myResources.GetColor(Resource.Color.notepad_lines);
paperColor = myResources.GetColor(Resource.Color.notepad_paper);
margin = myResources.GetDimension(Resource.Dimension.notepad_margin);
}
protected override void OnDraw(Canvas canvas)
{
canvas.DrawLine(0, 0, Height, 0, linePaint);
canvas.DrawLine(0, Height, Width, Height, linePaint);
// Нарисуйте кромку
canvas.DrawLine(margin, 0, margin, Height, marginPaint);
// Переместите текст в сторону от кромки
canvas.Save();
canvas.Translate(margin, 0);
base.OnDraw(canvas);
canvas.Restore();
}
}
}
正在标记 todolist_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TodoListItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:scrollbars="vertical"
android:textColor="@color/notepad_text"
android:fadingEdge="vertical"
/>
我指向 TodoListItemView,但该名称不起作用,打开标记时出错。Java中也有一个例子,所以有包,都清楚
<?xml version="1.0" encoding="utf-8"?>
<com.paad.todolist.TodoListItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:scrollbars="vertical"
android:textColor="@color/notepad_text"
android:fadingEdge="vertical"
/>
给我看哪个名字?