0

我通过使用 OnDraw 方法在画布上绘制矩形创建了一个地图。这在三星 s2 上运行良好,但是当我将它安装在 s3 中时,画布似乎太小了。我该怎么办?

我使用 Surface 视图来绘制矩形。

4

1 回答 1

0

Galaxy S2 是 hdpi 而 S3 是 xhdpi,所以这可能就是矩形看起来更小的原因。我建议覆盖 onMeasure 然后根据画布的当前高度和宽度设置矩形的高度和宽度。

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int parentViewWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentViewHeight = MeasureSpec.getSize(heightMeasureSpec);
// ... take into account the parent's size as needed ...
super.onMeasure(
    MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY), 
    MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY));

}

编辑:刚刚意识到您说您使用 SurfaceView 来绘制矩形而不是 View。在您的 onDraw 中,只需获取画布的当前高度和宽度,然后根据这些尺寸绘制矩形,而不是硬编码矩形的固定尺寸。希望这可以帮助

于 2012-10-20T15:32:33.073 回答