不是我预期的答案——我放弃了尝试以这种方式处理这个问题——数据格式很难理解。这是扩展的 relativelayout 类的部分代码,该类旋转,保持其中的所有内容不变,它还保持左/右对齐正确并正确处理触摸事件。例如,它将允许嵌套的 Seekbar 位于任何方向,从而避免了对特殊情况下的 seekbar 的需要。
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);
// }