There are several stack overflow questions that deal with keeping the activity in a constant orientation, suggesting either to set android:screenOrientation (or this) or to deal with the configuration changes manually.
However, these answers do not solve the problem if one wants to keep the benefits of automatic layout for most of the views, but to keep one view in a constant orientation. For example I have one main view for the content (a bitmap) and optionally several "toolbars". When the device is rotated from portrait to landscape, I want the toolbars to re-layout automatically. On the other hand, the main content view has a bitmap, and this should rotate with the device. Here is a simple code I use in my onDraw:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap bm = ... // code to get a bitmap
if (bm != null) {
canvas.drawBitmap(bm,0,0,mPaint);
}
}
This obviously does not work as intended because when the device orientation changes, the view is relayout and its coordinate system rotates in this orientation change by 90 degrees with respect to the physical device. One way to compensate for that would be to use a Matrix-object to draw the bitmap with 90 degrees rotation if the device orientation has changed. However, then also the input coordinates would have to be changed in order to keep the view input points and the point on the bitmap in correspondence.
Therefore my question after this long explanation is: can I keep the view so that its coordinate system with respect to the device is not rotated when the orientation changes.
Here is a picture that expresses what I want and what I currently get (xy coordinate system for the view also illustrated).