0

嗨,我正在学习制作一个绘画应用程序,用户可以在其中画线。我按照网上的fingerpaint教程,onCreate部分如下:

public class ColoringPageActivity2 extends FragmentActivity implements ColorPickerDialog.OnColorChangedListener 
{    
    private Paint mPaint;
    private MaskFilter mEmboss;
    private MaskFilter mBlur;
    MyView mv;
    AlertDialog dialog;
    ActionBar actionBar;
    Dialog dialog_draw;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        setContentView(R.layout.coloring_activity2);
        mv = (MyView) findViewById(R.id.drawerView);      //replaced setContentView(mv);
        mv.setDrawingCacheEnabled(true);
        mv.setBackgroundResource(R.drawable.ic_stub);

        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setColor(0xFFFF0000);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(20);
    }

在同一个类中继续:ColoringPageActivity2

public class MyView extends View 
{
    private static final float MINP = 0.25f;
    private static final float MAXP = 0.75f;
    private Bitmap mBitmap;
    private Canvas mCanvas;
    private Path mPath;
    private Paint mBitmapPaint;
    Context context;

    public MyView(Context c) 
    {
        super(c);
        context = c;
        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) 
    {
         ....

coloring_activity.xml:

 <RelativeLayout
            android:id="@+id/drawing_panel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/layout_tool"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true" >

            <ImageView
                android:id="@+id/image_color"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/ic_stub" />

            <com.abc.abc.activity.ColoringPageActivity2.MyView
                android:id="@+id/drawerView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@android:color/transparent" />
        </RelativeLayout>

日志猫:

10-21 00:15:37.685: E/AndroidRuntime(24558): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.abc.abc.activity.ColoringPageActivity2.MyView" on path: /data/app/com.abc.abc-2.apk
10-21 00:15:37.685: E/AndroidRuntime(24558):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
10-21 00:15:37.685: E/AndroidRuntime(24558):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-21 00:15:37.685: E/AndroidRuntime(24558):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-21 00:15:37.685: E/AndroidRuntime(24558):    at android.view.LayoutInflater.createView(LayoutInflater.java:565)
10-21 00:15:37.685: E/AndroidRuntime(24558):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
10-21 00:15:37.685: E/AndroidRuntime(24558):    ... 23 more

问题:

按照fingerpaint的例子,原来是setContentView(mv)and mv = new MyView(this);,是全屏绘画页面。相反,我想在底部添加一些按钮,所以我设计了一个自定义的 xml 并将其MyView放入 xml 中。

按下<com.abc.abc.activity.ColoringPageActivity2.MyView可以直接跳转到MyViewColoringActivity2`类中。

但是,运行ColoringPageActivity2时会弹出上面的logcat。

怎么可能解决?

谢谢!

4

1 回答 1

0

如果您将MyViewClass 放在一个单独的类中,它将起作用。就像 aButton或 aTextView是单独的类一样,如果您的类是单独的类,它肯定会起作用CustomViewActivity如果您需要,很容易调用另一个。

于 2014-10-20T17:15:06.107 回答