외부 클래스에서 생성 된 Canvas를 사용하려고합니다. 그러나 앱이 실행되지 않습니다. 여기에 내가 볼 수있는 내가 태그 com.myimage2.DemoView을 제거하면android에서 Canvas 사용하기
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DemoView extends View{
public DemoView(Context context){
super(context);
}
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
// make the entire canvas white
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
paint.setAntiAlias(false);
paint.setColor(Color.GREEN);
canvas.drawRect(100, 5, 200, 30, paint);
canvas.drawLine(0, 300 , 320, 300, paint);
}
}
레이아웃
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:scaleType="matrix"
android:layout_height="525px">
</ImageView>
<view class="com.test.DemoView"
android:id="@+id/demo"
android:layout_width="fill_parent"
android:layout_height="125px"/>
</LinearLayout>
다음과 같은 활동이
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
public class MyImage2 extends Activity {
DemoView draw;
private int imageSizeX = 2047;
private int imageSizeY = 2047;
private int current_drawable = R.drawable.image;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("blah", current_drawable);
ImageView img=(ImageView)findViewById(R.id.imageView);
Bitmap bmp=BitmapFactory.decodeResource(getResources() ,current_drawable);
draw = (DemoView)findViewById(R.id.demo);
imageSizeX = bmp.getWidth()/2;
imageSizeY = bmp.getHeight()/2;
Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, imageSizeX, imageSizeY, true);
img.setImageBitmap(resizedbitmap);
}
}
내 DemoView을 시작 MyImge 내 코드입니다 그러나 내 목표는 이미지와 캔버스를 보는 것입니다. 제발 누군가 도와주세요.
오류 로그 : 사전에
!ENTRY com.android.ide.eclipse.adt 2 0 2011-04-10 02:19:27.204
!MESSAGE AndroidManifest: Ignoring unknown 'com.test.DemoView' XML element
!ENTRY com.android.ide.eclipse.adt 2 0 2011-04-10 02:19:27.891
!MESSAGE AndroidManifest: Ignoring unknown 'view' XML element
많은 감사합니다.
프로젝트를 청소 해보십시오. 뷰 요소를 알고 있어야합니다. – MByD