0
我写了下面的观点:如何将我的自定义视图添加到XML布局?
public class EllipseView extends View {
private final Paint paint = new Paint();
public EllipseView(Context context) {
super(context);
paint.setColor(Color.RED);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawOval(new RectF(0, 0, getWidth(), getHeight()), paint);
}
}
如何增加它在XML布局?以下不工作(调试器没有连接):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View class="com.incubation.EllipseView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="200dp"
/>
</RelativeLayout>
ADDON
也有与Eclipse和设备,这需要重新启动才能解决