0

我写了以下视图:

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>

添加在

与 Eclipse 和 Device 通信也存在问题,需要重新启动才能修复

4

2 回答 2

2

你有没有尝试过:

<com.incubation.EllipseView
    android...
    />
于 2012-05-04T21:25:01.697 回答
1

尝试

<com.incubation.EllipseView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginLeft="200dp"
    android:layout_marginTop="200dp"
/>
于 2012-05-04T21:37:55.313 回答