开发者

help: simple drawing view/program

I'm trying to create the simplest 2D drawing program possible to isolate what exactly I can't figure out about drawing. This program should literally just draw a 20x20 rectangle. Here's what I have:

layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <com.example.drawing
     android:id="@+id/DrawView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     />   
</FrameLayout>

DrawView:

package com.example.drawing;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;


public class DrawView extends View{


    Paint mPaint;


    public DrawView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setFocusable(true);
        initDrawView();
    }

    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setFocusable(true);
        initDrawView();
    }

    public void initDrawView(){
        mPaint = new Paint();
        mPaint.setColor(0xFF000000);
    }

    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(0,0,20,20, mPaint);
    }





}

Activity:

package com.example.drawing;

import android.app.Activity;
import android.os.Bundle;

public class HelloDraw extends Activity {
    private DrawView dr;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

This program won't run. What is it that i am mi开发者_Go百科ssing? I am sure it is something absurdly obvious, but I just can't seem to find it.


From your exception, it's expecting that com.example.drawing from the tag name in your layout is the name of a class you've supplied. Your fully qualified class name is com.example.drawing.DrawView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜