0
A
回答
0
以下是旋转图像的示例代码。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
baseView = (View) findViewById(R.id.baseView);
turntable = (ImageView) findViewById(R.id.turntable);
turntable.setOnTouchListener(onTableTouched);
baseView.setOnTouchListener(onTableTouched);
}
public android.view.View.OnTouchListener onTableTouched = new android.view.View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent evt) {
double r = Math.atan2(evt.getX() - turntable.getWidth()/2,
(turntable.getHeight()/2) - evt.getY());
int rotation = (int) Math.toDegrees(r);
Log.i("R is ", ""+r);
if (evt.getAction() == MotionEvent.ACTION_DOWN) {
}
if (evt.getAction() == MotionEvent.ACTION_MOVE) {
x= evt.getX();
y= evt.getY();
updateRotation(rotation);
}
if (evt.getAction() == MotionEvent.ACTION_UP) {
//
}
return true;
}
};
private void updateRotation(double rot) {
float newRot = new Float(rot);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.orsl_circle_transparent);
Matrix matrix = new Matrix();
// matrix.setTranslate(getWindowManager().getDefaultDisplay().getWidth()/2, getWindowManager().getDefaultDisplay().getHeight());
matrix.postRotate(newRot,bitmap.getWidth()/2,bitmap.getHeight()/2);
// matrix.setSinCos(newRot, newRot/2, 100, 100);
// matrix.postRotate(newRot);
Log.i("THE ROATTION ", " "+ newRot);
if(y>250)
{
Bitmap redrawnBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap
.getWidth(), bitmap.getHeight(), matrix, true);
turntable.setImageBitmap(redrawnBitmap);
}else
{
Bitmap redrawnBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap
.getWidth(), bitmap.getHeight(), matrix, true);
turntable.setImageBitmap(redrawnBitmap);
Log.i("GUITAR _IMAGE", "");
}
}
0
你需要键入 “补间动画” 的使用XML。比起java代码,你可以根据这个xml做出一个视图行为。 这里是一个链接,帮助: http://www.edumobile.org/android/android-beginner-tutorials/tween-animation/
+0
Hi Roiberg,我想基于onTouch()方向旋转此图像。我必须使用这个旋转图像音量控制器。所以,必须通过onTouch监听器来实现这个循环。如果我们在xml文件中使用,onTouch控件将不会发生。感谢您的回复。 – Rajesh 2012-04-23 10:00:41
相关问题
- 1. 如何通过代码旋转图像?
- 2. 通过CSS旋转图像
- 3. 如何通过图库打开图像时如何旋转图像?
- 4. 通过jQuery旋转动态图像
- 5. 通过office.js旋转图像帧
- 6. Android图像通过xml文件旋转
- 7. 通过普通图像旋转的无损图像示例
- 8. 如何通过画布旋转位图
- 9. jQueryrotate如何通过光标旋转多个图像
- 10. 如何通过底部中心旋转图像?
- 11. 如何通过触摸侦听器来旋转图像?
- 12. 如何旋转图像?
- 13. 如何旋转图像帧?
- 14. 如何旋转图像wpf
- 15. 只能通过处理程序进行旋转图像,而不能通过图像本身进行旋转
- 16. 如何通过360度不同的图像旋转图像,触摸事件?
- 17. 旋转图像
- 18. - 旋转图像
- 19. 旋转图像
- 20. 旋转图像
- 21. 旋转图像
- 22. 旋转图像
- 23. 如何旋转图像视图?
- 24. 如何旋转位图图像
- 25. 我旋转图像倒过来,但如何水平翻转它
- 26. 通过单击按钮来旋转图像视图
- 27. KinectJS:通过拖放旋转关于绝对旋转点的图像
- 28. Android手动旋转ViewPager图像(通过按钮单击)而不旋转手机
- 29. 如何通过gridView添加OnTouchListener?
- 30. Javascript/jQuery图像旋转,如
在这段代码中,图像旋转但也改变其位置。 – Rajesh 2012-04-23 09:48:04