2011-03-10 2 views
0

View 클래스의 하위 클래스 인 inner 클래스를 사용하고 있습니다. 다음은클래스 뷰를 inflating하는 중 오류가 발생했습니다. android의 뷰

public static class MyView extends View { 
    private Bitmap mBitmap, bg_bmp; 
    private Canvas mCanvas; 
    private Path mPath; 
    private Paint mBitmapPaint; 

    public MyView(Context c, AttributeSet attrs) { 
     super(c, attrs); 
     Bitmap bmp_canvas = BitmapFactory.decodeResource(getResources(), R.drawable.bg_fun_game_draw_canvas); 
     mBitmap = Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bg_fun_game_draw_canvas), 0, 0, bmp_canvas.getWidth(), bmp_canvas.getHeight()); 
     mCanvas = new Canvas(mBitmap); 
     mPath = new Path(); 
     mBitmapPaint = new Paint(Paint.DITHER_FLAG); 
    } 

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

    @Override 
    protected void onDraw(Canvas canvas) { 
     canvas.drawColor(0xFFAAAAAA); 

     canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); 

     canvas.drawPath(mPath, mPaint); 
    } 

    private float mX, mY; 
    private static final float TOUCH_TOLERANCE = 4; 

    private void touch_start(float x, float y) { 
     mPath.reset(); 
     mPath.moveTo(x, y); 
     mX = x; 
     mY = y; 
    } 

    private void touch_move(float x, float y) { 
     float dx = Math.abs(x - mX); 
     float dy = Math.abs(y - mY); 
     if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { 
      mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); 
      mX = x; 
      mY = y; 
     } 
    } 

    private void touch_up() { 
     mPath.lineTo(mX, mY); 
     // commit the path to our offscreen 
     mCanvas.drawPath(mPath, mPaint); 
     // kill this so we don't double draw 
     mPath.reset(); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     float x = event.getX(); 
     float y = event.getY(); 

     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       touch_start(x, y); 
       invalidate(); 
       break; 
      case MotionEvent.ACTION_MOVE: 
       touch_move(x, y); 
       invalidate(); 
       break; 
      case MotionEvent.ACTION_UP: 
       touch_up(); 
       invalidate(); 
       break; 
     } 
     return true; 
    } 
} 

은 XML 레이아웃 코드입니다 :

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/bg_fun_game_draw_bottom" 
android:orientation="vertical" > 
    <view xmlns:android="http://schemas.android.com/apk/res/android" 
    class="mypackage.android.DrawGame$MyView" 
    android:id="@+id/linedraw" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical" 
    android:fadingEdge="vertical" 
    android:layout_gravity="center_horizontal" /> 
</LinearLayout> 

나는 다음과 같은 오류가 점점 오전 :

android.view.InflateException : 바이너리 XML 파일을 아래 내부 클래스의 코드는 줄 # 75 : 클래스보기를 확대하는 중 오류가 발생했습니다.

이 문제를 해결하는 데 도움을주십시오.

+0

디스플레이 스택 추적 – vnshetty

답변

1

비트 맵 크기가보기에서 사용 가능한 공간보다 높기 때문에이 문제가 발생합니다.

0

는 대신

<view class="mypackage.android.DrawGame$MyView" 

보십시오. 네임 스페이스가 이미 정의되어 있습니다.

+0

제안했지만 그대로 사용해도 같은 오류가 발생합니다. –