當前位置:首頁 » 安卓系統 » 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;
    }

    }
    熱點內容
    c語言相反數 發布:2025-01-23 22:28:55 瀏覽:187
    壓縮網課 發布:2025-01-23 22:13:19 瀏覽:597
    網站收錄源碼 發布:2025-01-23 22:04:42 瀏覽:693
    用c語言製作 發布:2025-01-23 21:49:09 瀏覽:951
    怎麼刪除開機密碼電腦 發布:2025-01-23 21:47:24 瀏覽:891
    php配置偽靜態 發布:2025-01-23 21:31:46 瀏覽:764
    mud源碼下載 發布:2025-01-23 21:19:46 瀏覽:137
    反恐精英15游戲伺服器ip 發布:2025-01-23 21:13:38 瀏覽:853
    起床的戰爭玩什麼伺服器 發布:2025-01-23 21:03:06 瀏覽:145
    企業級安卓手機防毒軟體哪個好 發布:2025-01-23 20:59:28 瀏覽:243