안드로이드 개발 질문/답변
(글 수 45,052)
package com.Todo_List;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
public class TodoListItemView extends TextView {
public TodoListItemView(Context context, AttributeSet attrs, int ds) {
super(context, attrs, ds);
// TODO Auto-generated constructor stub
init();
}
public TodoListItemView(Context context){
super(context);
init();
}
public TodoListItemView(Context context,AttributeSet attrs){
super(context,attrs);
init();
}
private Paint marginPaint;
private Paint linePaint;
private int paperColor;
private float margin;
private void init(){
//리소스 테이블에 대한 레퍼런스를 얻어온다.
Resources myResources = getResources();
//onDraw 메서드에서 사용할 페인트 브러시를 만든다.
marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
marginPaint.setColor(myResources.getColor(R.color.notepad_margin));
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(myResources.getColor(R.color.notepad_lines));
//종이 배경 색상과 여백 폭을 얻어온다.
paperColor = myResources.getColor(R.color.notepad_paper);
margin = myResources.getDimension(R.dimen.notepad_margin);
}
@Override
public void onDraw(Canvas canvas){
//종이 색으로 칠한다.
canvas.drawColor(paperColor);
//괘선을 그린다.
canvas.drawLine(0,0, getMeasuredHeight(), 0, linePaint);
canvas.drawLine(0,getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(),
linePaint);
//텍스트를 여백 바로 맞은편 이동한다.
canvas.save();
canvas.translate(margin, 0);
//기본 TextView를 사용해 텍스트를 렌더링한다.
super.onDraw(canvas);
}
}
R.dimen. 이런부분들이 계속 에러가 납니다.. 왜 에러가 나는지 모르겠어요..
책에 있는 예제를 그래로 따라 쳐보고 있는데도 에러가 납니다...
어떤 부분이 빠져 있어서 그런가요??
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
public class TodoListItemView extends TextView {
public TodoListItemView(Context context, AttributeSet attrs, int ds) {
super(context, attrs, ds);
// TODO Auto-generated constructor stub
init();
}
public TodoListItemView(Context context){
super(context);
init();
}
public TodoListItemView(Context context,AttributeSet attrs){
super(context,attrs);
init();
}
private Paint marginPaint;
private Paint linePaint;
private int paperColor;
private float margin;
private void init(){
//리소스 테이블에 대한 레퍼런스를 얻어온다.
Resources myResources = getResources();
//onDraw 메서드에서 사용할 페인트 브러시를 만든다.
marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
marginPaint.setColor(myResources.getColor(R.color.notepad_margin));
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(myResources.getColor(R.color.notepad_lines));
//종이 배경 색상과 여백 폭을 얻어온다.
paperColor = myResources.getColor(R.color.notepad_paper);
margin = myResources.getDimension(R.dimen.notepad_margin);
}
@Override
public void onDraw(Canvas canvas){
//종이 색으로 칠한다.
canvas.drawColor(paperColor);
//괘선을 그린다.
canvas.drawLine(0,0, getMeasuredHeight(), 0, linePaint);
canvas.drawLine(0,getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(),
linePaint);
//텍스트를 여백 바로 맞은편 이동한다.
canvas.save();
canvas.translate(margin, 0);
//기본 TextView를 사용해 텍스트를 렌더링한다.
super.onDraw(canvas);
}
}
R.dimen. 이런부분들이 계속 에러가 납니다.. 왜 에러가 나는지 모르겠어요..
책에 있는 예제를 그래로 따라 쳐보고 있는데도 에러가 납니다...
어떤 부분이 빠져 있어서 그런가요??