android 控件方向旋转90度,android – 旋转视图层次90度

我正在工作的一个子类的FrameLayout,应该是将所有的孩子旋转90度。我这样做是为了克服Android 2.1及以下版本中仅存在于风景中的摄像机限制,将活动放置在横向,但将我的摄像机覆盖放置在此framelayout覆盖中,以使其看起来像是纵向(

this is how Layar does it)到完成这个,我适应

Jeff Sharkey’s code旋转视图。我的问题是,我可以旋转Framelayout,但我不能调整它以匹配新的维度。所以在我的g1,而不是一个320×480纵向视图在480×320相机视图的风景,我得到一个320×320盒子在中间显示我的肖像视图与侧面切碎。

这里是我的代码到目前为止:

public class RotateLayout extends FrameLayout {

private Matrix mForward = new Matrix();

private Matrix mReverse = new Matrix();

private float[] mTemp = new float[2];

public RotateLayout(Context context) {

super(context);

}

public RotateLayout(Context context, AttributeSet attrs) {

super(context, attrs);

}

/* (non-Javadoc)

* @see android.widget.FrameLayout#onMeasure(int, int)

*/

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

//This didn't work:

//super.onMeasure(heightMeasureSpec, widthMeasureSpec);

}

/* (non-Javadoc)

* @see android.widget.FrameLayout#onSizeChanged(int, int, int, int)

*/

@Override

protected void onSizeChanged(int w, int h, int oldw, int oldh) {

super.onSizeChanged(w, h, oldw, oldh);

}

@Override

protected void dispatchDraw(Canvas canvas) {

canvas.rotate(270, getWidth()/2, getHeight()/2);

//This code will stretch the canvas to accommodate the new screen size. This is not what I want.

//float scaleX=(float)getHeight()/getWidth();

//float scaleY=(float)getWidth()/getHeight();

//canvas.scale(scaleX, scaleY, getWidth()/2, getHeight()/2);

mForward = canvas.getMatrix();

mForward.invert(mReverse);

canvas.save();

canvas.setMatrix(mForward); //This is the matrix we need to use for proper positioning of touch events

super.dispatchDraw(canvas);

canvas.restore();

}

@Override

public boolean dispatchTouchEvent(MotionEvent event) {

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);

}

}

我已经尝试覆盖OnMeasure切换视图的X和Y维度,但还没有能够让它工作。

您可以提供任何帮助,非常感谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值