我写了以下观点:
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和Device进行通信时也存在问题,需要重新启动才能修复
答案 0 :(得分:2)
你试过了吗?
<com.incubation.EllipseView
android...
/>
答案 1 :(得分:1)
尝试
<com.incubation.EllipseView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="200dp"
/>