如何让一个圆围绕轴心转一定的角度

hzgmm 2012-09-29 09:15:17
让一个圆形图片围绕圆心(轴心)旋转一定的角度,要用到什么哪个函数?每点击一次上下键就旋转一定角度!

谢谢
...全文
171 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
编号27149 2012-09-29
  • 打赏
  • 举报
回复
/**
* 图片旋转指定角度
* @param resizedBitmap 位图
* @param image View
* @param scaleAngle 旋转角度值
* @return
*/
private ImageView pointerRotation(Bitmap resizedBitmap,ImageView image,int scaleAngle)
{

//scaleAngle=360-45+scaleAngle;

int ScaleTimes=1;

int oldWidth = resizedBitmap.getWidth();
int oldHeight = resizedBitmap.getHeight() ;

/* ScaleTimes=1,维持1:1的宽高比例*/
int newWidth = resizedBitmap.getWidth()*ScaleTimes ;
int newHeight = resizedBitmap.getHeight()*ScaleTimes ;

float scaleWidth = (float) newWidth / resizedBitmap.getWidth();
float scaleHeight = (float) newHeight / resizedBitmap.getHeight();

Matrix matrix = new Matrix();
/* 使用Matrix.postScale设定维度 */
matrix.postScale(scaleWidth, scaleHeight);
/* 使用Matrix.postRotate方法旋转Bitmap*/
//matrix.postRotate(5*ScaleAngle);
matrix.setRotate(scaleAngle);
/* 建立新的Bitmap对象 */
resizedBitmap =Bitmap.createBitmap(resizedBitmap, 0, 0, oldWidth, oldHeight, matrix, true);
/**/
BitmapDrawable myNewBitmapDrawable =new BitmapDrawable(resizedBitmap);
image.setImageDrawable(myNewBitmapDrawable);


//imageView1.image.setBackgroundResource(R.drawable.mainbuttoneffect);

int h=resizedBitmap.getHeight();
int w=resizedBitmap.getWidth();
image.setLayoutParams ( new AbsoluteLayout.LayoutParams (w,h,(int) (screenW-w)/2,(int)(screenH-2*h)/2 ));

SourceLocationX=(screenW-w)/2;
SourceLocationY=(screenH-2*h)/2;


return image;
}

zh


这是我从程序中截取的函数,试着改成你想要的,应该可以满足你的
j_f0001 2012-09-29
  • 打赏
  • 举报
回复
两种方法
1.canvas.rotate(角度);
2.使用Matrix进行矩阵变化.

80,392

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧