我想在Gallery布局中显示一系列我自己的Descedent类View,但是当它显示时,我在画廊中的每个自定义视图都太大了,即它们超出了边框。
我已经(在XML中)将每个视图的背景设置为"android:galleryItemBackground"
并在我的后代View类中处理onMeasure()等,但由于某种原因,我的视图总是比背景大。
有人可以告诉我在自定义视图类中需要实现的其他内容吗?
由于
onDraw()方法在这里:
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;
}
答案 0 :(得分:1)
当您使用LayoutParams
方法收到自定义观看次数时,请尝试将其设为Adapter.getView()
。