私が期待していた答えとはまったく違いました - 私はこれをまったくそのように処理しようとすることをあきらめました - データ形式は理解するのが非常に困難でした. これは、内部のすべてを変更せずに回転し、左右の配置を正しく保ち、タッチ イベントを正しく処理する、拡張された relativelayout クラスのコードの一部です。たとえば、ネストされたシークバーを任意の方向に配置できるため、特殊なケースのシークバーが不要になります。
public void setOrientation() {
if (rSource == RotateSetBy.globalStatic) {
currRotate = PootleViewExtras.deviceOrient;
}
boolean isVert = currRotate == Orientations.up || currRotate == Orientations.down;
if (lockSize > 0 && widthAtt < 0 && heightAtt < 0) {
int lws = 0;
int lhs = 0;
if (isVert) {
lws = widthAtt;
lhs = heightAtt;
} else {
lhs = widthAtt;
lws = heightAtt;
}
int setgrav = gravityAtt & 0x11; // messy but seems to do the right things
if (currRotate == Orientations.down ) {
if ((gravityAtt & 0x2) != 0) setgrav |= 0x4;
if ((gravityAtt & 0x4) != 0) setgrav |= 0x2;
if ((gravityAtt & 0x20) != 0) setgrav |= 0x40;
if ((gravityAtt & 0x40) != 0) setgrav |= 0x20;
} else {
setgrav = gravityAtt;
}
FrameLayout.LayoutParams reset = new FrameLayout.LayoutParams (lws, lhs, setgrav);
this.setLayoutParams(reset);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
boolean isVert = currRotate == Orientations.up || currRotate == Orientations.down;
if (isVert) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
lastWidth = this.getMeasuredWidth();
lastHeight = this.getMeasuredHeight();
} else {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
lastHeight = this.getMeasuredWidth();
lastWidth = this.getMeasuredHeight();
}
setMeasuredDimension(lastWidth,lastHeight);
switch (currRotate) {
case up:
mForward.reset();
mForward.postRotate(0);
mForward.invert(mReverse);
break;
case right:
mForward.reset();
mForward.postRotate(90,lastWidth/2,lastWidth/2);
mForward.invert(mReverse);
break;
case down:
mForward.reset();
mForward.postRotate(180,lastWidth/2,lastHeight/2);
mForward.invert(mReverse);
break;
case left:
mForward.reset();
mForward.postRotate(-90,lastHeight/2,lastHeight/2);
mForward.invert(mReverse);
break;
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
if (currRotate == Orientations.up) {
super.dispatchDraw(canvas);
} else {
canvas.save();
canvas.concat(mForward);
super.dispatchDraw(canvas);
canvas.restore();
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
// if (currRotate == Orientations.up){
// return super.dispatchTouchEvent(event);
// } else {
final float[] temp = mTemp;
temp[0] = event.getX();
temp[1] = event.getY();
mReverse.mapPoints(temp);
event.setLocation(temp[0], temp[1]);
return super.dispatchTouchEvent(event);
// }