0
필자는 작성한 View CropView를 사용하는 Activity CropActivity를 보유하고 있습니다. CropView는 SelectorView (자체 작성)를 확장하고 SelectorView는 ImageView를 확장합니다.Android를 사용할 때 NoSuchMethodException이 throw됩니다.
CropActivity를 시작하면 NoSuchMethodException이 발생합니다. CropActivity에 대해 SelectorView를 사용할 때 오류가 발생하지 않습니다.
공용 클래스 CropView이 SelectorView를 확장하는 Cropview 클래스 {
public CropView(Context context) {
super(context);
initCropView();
}
private void initCropView() {
setmPaintColor(Color.WHITE);
setsMinimumSize(metrics.densityDpi);
setsTouchBuffer(metrics.densityDpi/3);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (getmLeftTop().equals(0, 0))
resetPoints();
// draw the points on the screen; one in every corner and one in the center
canvas.drawRect(getmLeftTop().x, getmLeftTop().y, getmRightBottom().x, getmRightBottom().y,
getmPaint());
canvas.drawCircle(getmLeftTop().x, getmLeftTop().y, 40, getmPaint());
canvas.drawCircle(getmLeftTop().x, getmRightBottom().y, 40, getmPaint());
canvas.drawCircle(getmRightBottom().x, getmLeftTop().y, 40, getmPaint());
canvas.drawCircle(getmRightBottom().x, getmRightBottom().y, 40, getmPaint());
canvas.drawCircle(getmCenter().x, getmCenter().y, 10, getmPaint());
}
Selectorview는 한 OnCreate CropActivity
에서public SelectorView(Context context) {
super(context);
initSelectorView();
}
public SelectorView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
initSelectorView();
}
public SelectorView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initSelectorView();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
/**
* Initializes the cropview and variables.
*/
private void initSelectorView() {
mPaint.setStyle(Style.STROKE);
mPaint.setStrokeWidth(5);
mLeftTop = new Point();
mRightBottom = new Point();
mCenter = new Point();
mScreenCenter = new Point();
mPrevious = new Point();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int eventaction = event.getAction();
switch (eventaction) {
// set the touch point
case MotionEvent.ACTION_DOWN:
mPrevious.set((int) event.getX(), (int) event.getY());
break;
니펫을
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crop);
mContext = this;
mCropView = new CropView(this);
mFile = new File(getIntent().getStringExtra("imgpath"));
mBitmaps = new ArrayList<Bitmap>();
mTasks = new ArrayList();
mNumberOfCores = Runtime.getRuntime().availableProcessors();
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setTitle("Enhancing image");
mBitmapDrawable = null;
mBitmapDrawable = (BitmapDrawable) Drawable.createFromPath(mFile.getAbsolutePath());
mCropView = (CropView) findViewById(R.id.image_preview);
mCropView.setImageDrawable(mBitmapDrawable);
mCropButton = (Button) findViewById(R.id.button_crop);
아이디어는 우리에게 몇 가지 코드를 보여 주면 생성됩니다 .. :) –
코드는 없습니다. –