The documentation says about Canvas.getHeight():
Returns the height of the current drawing layer
Is this as much the case for API < 16?
Example:
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
class MyView extends View {
Rect r = new Rect();
public MyView(Context context) {
super(context);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(20, 40);
params.leftMargin = 50;
params.topMargin = 50;
setLayoutParams(params);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.rgb(255, 0, 0));
Log.d("me", "canvas.getHeight = " + canvas.getHeight());
Log.d("me", "canvas.getWidth = " + canvas.getWidth());
canvas.getClipBounds(r);
Log.d("me", ".getClipBounds.height() = " + r.height());
Log.d("me", ".getClipBounds.widht() = " + r.width());
}
}
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout container = new FrameLayout(this);
container.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
container.addView(new MyView(this));
setContentView(container);
}
}
API >= 16:
If I am using an emulator like Galaxy Nexus with API 16 or above canvas.getHeight() returns 40, as expected:
D/me﹕ canvas.getHeight = 40
D/me﹕ canvas.getWidth = 20
D/me﹕ .getClipBounds.height() = 40
D/me﹕ .getClipBounds.widht() = 20
API < 16:
But If I am using an emulator like Galaxy Nexus with API 15 or below (also tried this with a real device and API 7):
D/me﹕ canvas.getHeight = 1280
D/me﹕ canvas.getWidth = 720
D/me﹕ .getClipBounds.height() = 40
D/me﹕ .getClipBounds.widht() = 20
Question:
Why are the results different? I could not find any hint in the documentation.