I want to display a series of my own descendent class of View in a Gallery layout but when it is displayed, each of my custom views in the gallery is too large i.e. they exceed the border.
I've set (in XML) the background for each view as "android:galleryItemBackground"
and handle onMeasure() etc in my descendent View class but for some reason my view is always drawn larger than the background.
Could anyone give开发者_开发知识库 me any idea what else I need to implement in my custom view class?
Thanks
The onDraw() method is here:
protected void onDraw(Canvas canvas){
/* Draw dial scale-arc */
canvas.drawArc(scaleArcRect, scaleArcStart, scaleArcSweep, false, scaleArcPaint);
canvas.drawArc(innerScaleArcRect, scaleArcStart, scaleArcSweep, false, innerScaleArcPaint);
/* Draw the scale-arc ticks */
drawScaleTicks(canvas);
/* Add text to dial */
//canvas.drawText(scaleFactorText, sFactorTextRect.left, sFactorTextRect.bottom, scaleTextPaint);
drawScaleLegend(canvas);
/*Draw the pointer */
canvas.save();
canvas.rotate(drawAngle,this.viewWidth/2,this.viewHeight/2);
canvas.drawPath(pointerPath, pointerPaint);
canvas.restore();
//canvas.drawText(scaleFactorText, sFactorTextRect.left,this.viewHeight/2, scaleTextPaint);
/* Update position feedback variables */
actualAngle = drawAngle;
/* signal to compute thread that the position has been updated */
isCommanded = false;
}
Try giving your custom views a LayoutParams
when you receive them from the Adapter.getView()
method.
精彩评论