当前位置:首页 » 安卓系统 » android手势旋转

android手势旋转

发布时间: 2022-07-18 15:45:31

❶ android开发 实现一个可以由手势控制的转盘

这个问题有点复杂。

这个复写一个新的ViewGroup ,这个ViewGroup里面 绘制你的 转盘,转盘应该是圆的吧,然后加入三个按钮,手势就是复写onTouch事件去判断手势是左边还是右边 还是上边 下边。

❷ 如何在android中加入一个用3dsmax制作的3D模型,并让他根据手势旋转

写一个3d模型浏览器app,必须支持你的模型格式,加入手势操作

❸ android中怎么实现随手指移动物体围绕一个点的转动

用旋转,我忘记了是什么类了,总之就是矩阵运算,然后随着手指的坐标实时计算出需要旋转的角度,然后再把图片旋转后画出来。

❹ android顺时针旋转手势和逆时针旋转手势

ontouch的监听可以获取到划过的点的坐标,你在数据处理一下就行了。

❺ android开发中 顺时针或者逆时针旋转手势如何检测

这个真心不好判断,因为6也是个逆时针,这个起点终点和轨迹都不好判断

❻ 求助,怎么用android实现控件的3D立体旋转效果

  • 实现水平滑动,所以可在手势抬起的时候进行判断并处理,是滑动显得流畅,代码如下:

java">packagecom.example.rotation3dview;
importandroid.content.Context;
importandroid.graphics.Camera;
importandroid.graphics.Canvas;
importandroid.graphics.Matrix;
importandroid.util.AttributeSet;
importandroid.view.MotionEvent;
importandroid.view.VelocityTracker;
importandroid.view.View;
importandroid.view.ViewDebug.HierarchyTraceType;
importandroid.view.ViewGroup;
importandroid.widget.ImageView;
importandroid.widget.Scroller;

{
privateintmCurScreen=1;
//滑动的速度
privatestaticfinalintSNAP_VELOCITY=500;
;
privateintmWidth;
privateScrollermScroller;
privateCameramCamera;
privateMatrixmMatrix;
//旋转的角度,可以进行修改来观察效果
privatefloatangle=90;
publicRote3DView(Contextcontext,AttributeSetattrs){
super(context,attrs);
mScroller=newScroller(context);
mCamera=newCamera();
mMatrix=newMatrix();
initScreens();
}

publicvoidinitScreens(){
ViewGroup.LayoutParamsp=newViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
for(inti=0;i<3;i++){
this.addView(newImageView(this.getContext()),i,p);
}
((ImageView)this.getChildAt(0)).setImageResource(R.drawable.page1);
((ImageView)this.getChildAt(1)).setImageResource(R.drawable.page2);
((ImageView)this.getChildAt(2)).setImageResource(R.drawable.page3);
}

@Override
protectedvoidonLayout(booleanchanged,intl,intt,intr,intb){
intchildLeft=0;
finalintchildCount=getChildCount();
for(inti=0;i<childCount;i++){
finalViewchildView=getChildAt(i);
if(childView.getVisibility()!=View.GONE){
finalintchildWidth=childView.getMeasuredWidth();
childView.layout(childLeft,0,childLeft+childWidth,childView.getMeasuredHeight());
childLeft+=childWidth;
}
}
}

@Override
protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec){
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
finalintwidth=MeasureSpec.getSize(widthMeasureSpec);
finalintwidthMode=MeasureSpec.getMode(widthMeasureSpec);
if(widthMode!=MeasureSpec.EXACTLY){
thrownewIllegalStateException("仅支持精确尺寸");
}
finalintheightMode=MeasureSpec.getMode(heightMeasureSpec);
if(heightMode!=MeasureSpec.EXACTLY){
thrownewIllegalStateException("仅支持精确尺寸");
}
finalintcount=getChildCount();
for(inti=0;i<count;i++){
getChildAt(i).measure(widthMeasureSpec,heightMeasureSpec);
}
scrollTo(mCurScreen*width,0);
}

privatefloatmDownX;
@Override
publicbooleanonTouchEvent(MotionEventevent){
if(mVelocityTracker==null){
mVelocityTracker=VelocityTracker.obtain();
}
//将当前的触摸事件传递给VelocityTracker对象
mVelocityTracker.addMovement(event);
floatx=event.getX();
switch(event.getAction()){
caseMotionEvent.ACTION_DOWN:
if(!mScroller.isFinished()){
mScroller.abortAnimation();
}
mDownX=x;
break;
caseMotionEvent.ACTION_MOVE:
intdisX=(int)(mDownX-x);
mDownX=x;
scrollBy(disX,0);
break;
caseMotionEvent.ACTION_UP:
=mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000);
intvelocityX=(int)velocityTracker.getXVelocity();
if(velocityX>SNAP_VELOCITY&&mCurScreen>0){
snapToScreen(mCurScreen-1);
}elseif(velocityX<-SNAP_VELOCITY&&mCurScreen<getChildCount()-1){
snapToScreen(mCurScreen+1);
}else{
snapToDestination();
}
if(mVelocityTracker!=null){
mVelocityTracker.recycle();
mVelocityTracker=null;
}
break;
}
returntrue;
}

@Override
publicvoidcomputeScroll(){
if(mScroller.computeScrollOffset()){
scrollTo(mScroller.getCurrX(),mScroller.getCurrY());
postInvalidate();
}
}

publicvoidsnapToDestination(){
setMWidth();
finalintdestScreen=(getScrollX()+mWidth/2)/mWidth;
snapToScreen(destScreen);
}

publicvoidsnapToScreen(intwhichScreen){
whichScreen=Math.max(0,Math.min(whichScreen,getChildCount()-1));
setMWidth();
intscrollX=getScrollX();
intstartWidth=whichScreen*mWidth;
if(scrollX!=startWidth){
intdelta=0;
intstartX=0;
if(whichScreen>mCurScreen){
setPre();
delta=startWidth-scrollX;
startX=mWidth-startWidth+scrollX;
}elseif(whichScreen<mCurScreen){
setNext();
delta=-scrollX;
startX=scrollX+mWidth;
}else{
startX=scrollX;
delta=startWidth-scrollX;
}
mScroller.startScroll(startX,0,delta,0,Math.abs(delta)*2);
invalidate();
}
}

privatevoidsetNext(){
intcount=this.getChildCount();
Viewview=getChildAt(count-1);
removeViewAt(count-1);
addView(view,0);
}

privatevoidsetPre(){
intcount=this.getChildCount();
Viewview=getChildAt(0);
removeViewAt(0);
addView(view,count-1);
}

privatevoidsetMWidth(){
if(mWidth==0){
mWidth=getWidth();
}
}
}
  • 实现立体效果,添加如下代码:

/*
*当进行View滑动时,会导致当前的View无效,该函数的作用是对View进行重新绘制调用drawScreen函数
*/
@Override
protectedvoiddispatchDraw(Canvascanvas){
finallongdrawingTime=getDrawingTime();
finalintcount=getChildCount();
for(inti=0;i<count;i++){
drawScreen(canvas,i,drawingTime);
}
}

publicvoiddrawScreen(Canvascanvas,intscreen,longdrawingTime){
//得到当前子View的宽度
finalintwidth=getWidth();
finalintscrollWidth=screen*width;
finalintscrollX=this.getScrollX();
//偏移量不足的时
if(scrollWidth>scrollX+width||scrollWidth+width<scrollX){
return;
}
finalViewchild=getChildAt(screen);
finalintfaceIndex=screen;
finalfloatcurrentDegree=getScrollX()*(angle/getMeasuredWidth());
finalfloatfaceDegree=currentDegree-faceIndex*angle;
if(faceDegree>90||faceDegree<-90){
return;
}
finalfloatcenterX=(scrollWidth<scrollX)?scrollWidth+width
:scrollWidth;
finalfloatcenterY=getHeight()/2;
finalCameracamera=mCamera;
finalMatrixmatrix=mMatrix;
canvas.save();
camera.save();
camera.rotateY(-faceDegree);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX,-centerY);
matrix.postTranslate(centerX,centerY);
canvas.concat(matrix);
drawChild(canvas,child,drawingTime);
canvas.restore();
}

    ❼ android中开发百度地图怎么设置地图不能旋转以及手势切换视角的问题

    MapController对象.setRotationGesturesEnabled(false);// 不使用缩放手势
    MapController对象.setOverlookingGesturesEnabled(false);// 不使用视角手势

    ❽ 如何通过手势实现android view 的 缩放 平移

    代码主要分两部分,一个activity一个view,代码如下:

    packagecom.example.touch;

    importandroid.app.Activity;
    importandroid.os.Bundle;

    {
    /**.*/
    @Override
    publicvoidonCreate(BundlesavedInstanceState){
    super.onCreate(savedInstanceState);
    TouchImageViewimg=newTouchImageView(this);
    setContentView(img);
    }
    }



    packagecom.example.touch;

    importandroid.graphics.Bitmap;
    importandroid.graphics.Bitmap.Config;
    importandroid.graphics.BitmapFactory;
    importandroid.graphics.Canvas;
    importandroid.graphics.Matrix;
    importandroid.graphics.PointF;
    importandroid.util.DisplayMetrics;
    importandroid.util.FloatMath;
    importandroid.view.MotionEvent;
    importandroid.widget.ImageView;

    {

    floatx_down=0;
    floaty_down=0;
    PointFstart=newPointF();
    PointFmid=newPointF();
    floatoldDist=1f;
    floatoldRotation=0;
    Matrixmatrix=newMatrix();
    Matrixmatrix1=newMatrix();
    MatrixsavedMatrix=newMatrix();

    privatestaticfinalintNONE=0;
    privatestaticfinalintDRAG=1;
    privatestaticfinalintZOOM=2;
    intmode=NONE;

    booleanmatrixCheck=false;

    intwidthScreen;
    intheightScreen;

    Bitmapgintama;

    publicTouchImageView(){
    super(activity);
    gintama=BitmapFactory.decodeResource(getResources(),R.drawable.gintama);

    DisplayMetricsdm=newDisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    widthScreen=dm.widthPixels;
    heightScreen=dm.heightPixels;

    matrix=newMatrix();
    }

    protectedvoidonDraw(Canvascanvas){
    canvas.save();
    canvas.drawBitmap(gintama,matrix,null);
    canvas.restore();
    }

    publicbooleanonTouchEvent(MotionEventevent){
    switch(event.getAction()&MotionEvent.ACTION_MASK){
    caseMotionEvent.ACTION_DOWN:
    mode=DRAG;
    x_down=event.getX();
    y_down=event.getY();
    savedMatrix.set(matrix);
    break;
    caseMotionEvent.ACTION_POINTER_DOWN:
    mode=ZOOM;
    oldDist=spacing(event);
    oldRotation=rotation(event);
    savedMatrix.set(matrix);
    midPoint(mid,event);
    break;
    caseMotionEvent.ACTION_MOVE:
    if(mode==ZOOM){
    matrix1.set(savedMatrix);
    floatrotation=rotation(event)-oldRotation;
    floatnewDist=spacing(event);
    floatscale=newDist/oldDist;
    matrix1.postScale(scale,scale,mid.x,mid.y);//缩放
    matrix1.postRotate(rotation,mid.x,mid.y);//旋转
    matrixCheck=matrixCheck();
    if(matrixCheck==false){
    matrix.set(matrix1);
    invalidate();
    }
    }elseif(mode==DRAG){
    matrix1.set(savedMatrix);
    matrix1.postTranslate(event.getX()-x_down,event.getY()
    -y_down);//平移
    matrixCheck=matrixCheck();
    matrixCheck=matrixCheck();
    if(matrixCheck==false){
    matrix.set(matrix1);
    invalidate();
    }
    }
    break;
    caseMotionEvent.ACTION_UP:
    caseMotionEvent.ACTION_POINTER_UP:
    mode=NONE;
    break;
    }
    returntrue;
    }

    privatebooleanmatrixCheck(){
    float[]f=newfloat[9];
    matrix1.getValues(f);
    //图片4个顶点的坐标
    floatx1=f[0]*0+f[1]*0+f[2];
    floaty1=f[3]*0+f[4]*0+f[5];
    floatx2=f[0]*gintama.getWidth()+f[1]*0+f[2];
    floaty2=f[3]*gintama.getWidth()+f[4]*0+f[5];
    floatx3=f[0]*0+f[1]*gintama.getHeight()+f[2];
    floaty3=f[3]*0+f[4]*gintama.getHeight()+f[5];
    floatx4=f[0]*gintama.getWidth()+f[1]*gintama.getHeight()+f[2];
    floaty4=f[3]*gintama.getWidth()+f[4]*gintama.getHeight()+f[5];
    //图片现宽度
    doublewidth=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    //缩放比率判断
    if(width<widthScreen/3||width>widthScreen*3){
    returntrue;
    }
    //出界判断
    if((x1<widthScreen/3&&x2<widthScreen/3
    &&x3<widthScreen/3&&x4<widthScreen/3)
    ||(x1>widthScreen*2/3&&x2>widthScreen*2/3
    &&x3>widthScreen*2/3&&x4>widthScreen*2/3)
    ||(y1<heightScreen/3&&y2<heightScreen/3
    &&y3<heightScreen/3&&y4<heightScreen/3)
    ||(y1>heightScreen*2/3&&y2>heightScreen*2/3
    &&y3>heightScreen*2/3&&y4>heightScreen*2/3)){
    returntrue;
    }
    returnfalse;
    }

    //触碰两点间距离
    privatefloatspacing(MotionEventevent){
    floatx=event.getX(0)-event.getX(1);
    floaty=event.getY(0)-event.getY(1);
    returnFloatMath.sqrt(x*x+y*y);
    }

    //取手势中心点
    privatevoidmidPoint(PointFpoint,MotionEventevent){
    floatx=event.getX(0)+event.getX(1);
    floaty=event.getY(0)+event.getY(1);
    point.set(x/2,y/2);
    }

    //取旋转角度
    privatefloatrotation(MotionEventevent){
    doubledelta_x=(event.getX(0)-event.getX(1));
    doubledelta_y=(event.getY(0)-event.getY(1));
    doubleradians=Math.atan2(delta_y,delta_x);
    return(float)Math.toDegrees(radians);
    }

    //将移动,缩放以及旋转后的图层保存为新图片
    //本例中没有用到该方法,需要保存图片的可以参考
    publicBitmapCreatNewPhoto(){
    Bitmapbitmap=Bitmap.createBitmap(widthScreen,heightScreen,
    Config.ARGB_8888);//背景图片
    Canvascanvas=newCanvas(bitmap);//新建画布
    canvas.drawBitmap(gintama,matrix,null);//画图片
    canvas.save(Canvas.ALL_SAVE_FLAG);//保存画布
    canvas.restore();
    returnbitmap;
    }

    }
    热点内容
    如何破解软件登录不了服务器 发布:2025-01-24 02:05:07 浏览:12
    春节三新算法 发布:2025-01-24 02:03:22 浏览:18
    我的世界服务器房间号2020电脑版 发布:2025-01-24 01:28:05 浏览:399
    微信提示存储空间不足 发布:2025-01-24 01:19:53 浏览:964
    安卓电脑管家如何清除缓存 发布:2025-01-24 00:55:42 浏览:148
    怎么上传歌曲到qq音乐 发布:2025-01-24 00:45:30 浏览:65
    养猫用什么配置 发布:2025-01-24 00:37:58 浏览:812
    pythongps 发布:2025-01-24 00:37:51 浏览:813
    办公编程鼠标 发布:2025-01-24 00:37:07 浏览:386
    wpa加密类型 发布:2025-01-24 00:35:58 浏览:960