0
customView를 만들고 있지만 표시하지 않습니다. 그것의 속성을 attrs.xml에 추가했습니다.사용자 지정보기가 그림이 아닙니다.
나는 생성자를 구현했지만 단순히 호와 타원을 그렸지만 표시하지는 않습니다.
오류는 표시하지 않지만 표시하지는 않습니다.
나는 내가 잘못 <package.above.Pie>
처럼 XML로를 추가 한 ... 당신의 onDraw() 메소드 폭의 값이 0 (영)으로 점점에서
public class Pie extends View
{
Context cont;
public int eventValue = 0;
RectF mediumOval;
RectF oval;
Paint p1;
Paint p2;
Paint p3;
Paint p4;
Paint p5;
RectF smallOval;
int width;
public Pie(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
cont = context;
final TypedArray styled = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Pie, 0, 0);
eventValue = styled.getInteger(R.styleable.Pie_eventValue, 16);
styled.recycle();
myInit();
}
public Pie(Context context, AttributeSet attrs)
{
this(context,attrs,0);
}
public Pie(Context context)
{
super(context);
cont = context;
myInit();
}
public void setEventValue(int eValue)
{
eventValue = eValue;
}
public void myInit()
{
width = getWidth();
p1 = new Paint(1);
p1.setColor(Color.rgb(86, 86, 86));
p1.setStyle(android.graphics.Paint.Style.FILL);
p2 = new Paint(1);
p2.setColor(Color.rgb(245, 109, 89));
p2.setStyle(android.graphics.Paint.Style.FILL);
p3 = new Paint(1);
p3.setColor(Color.rgb(71, 71, 71));
p3.setStyle(android.graphics.Paint.Style.FILL);
p4 = new Paint(1);
p4.setColor(Color.rgb(247, 247, 247));
p4.setStyle(android.graphics.Paint.Style.FILL);
p5 = new Paint(1);
p5.setColor(Color.rgb(246, 246, 246));
p5.setStyle(android.graphics.Paint.Style.FILL);
mediumOval = new RectF();
oval = new RectF();
smallOval = new RectF();
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
int i = width/4;
oval.set(i - i/2, i/2, i * 3 + i/2, i * 3 + i/2);
mediumOval.set(i - i/4, i - i/4, i * 3 + i/4, i * 3 + i/4);
smallOval.set(i, i, i * 3, i * 3);
canvas.drawOval(oval, p1);
canvas.drawArc(oval, -90F, (int)Math.round((360D * Double.valueOf(eventValue).doubleValue())/100D), true, p2);
canvas.drawOval(mediumOval, p3);
canvas.drawOval(smallOval, p1);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int desiredWidth = width;
int desiredHeight = width;
int widthMode = android.view.View.MeasureSpec.getMode(widthMeasureSpec);
int widthSize = android.view.View.MeasureSpec.getSize(widthMeasureSpec);
int heightMode = android.view.View.MeasureSpec.getMode(heightMeasureSpec);
int heightSize = android.view.View.MeasureSpec.getSize(heightMeasureSpec);
int measuredWidth;
int measuredHeight;
if (widthMode == MeasureSpec.EXACTLY)
{
measuredWidth = widthSize ;
}
else if (widthMode == MeasureSpec.AT_MOST)
{
measuredWidth = Math.min(desiredWidth , widthSize);
}
else
{
measuredWidth = desiredWidth;
}
if (heightMode == MeasureSpec.EXACTLY)
{
measuredHeight = heightSize ;
}
else if (heightMode == MeasureSpec.AT_MOST)
{
measuredHeight = Math.min(desiredHeight, heightSize);
}
else
{
measuredHeight = desiredHeight;
}
setMeasuredDimension(measuredWidth, measuredHeight);
}
}
즉, onDraw 호출 전에 getWidth를 사용할 수 없다는 의미입니다. – Nepster
아니요 onLayout() 및 onMeasure() 메서드에서 onDraw() 메서드보다 먼저 가로 세로를 얻을 수 있습니다 ... – Chandrakanth
감사합니다. 내 onMeasure 메서드가 정확합니다. customView를 만드는 방법에 대한 개념을 배우고 싶습니다. .suggest me some tutorial – Nepster