在本文中,您将会了解到关于计算触摸点的角度并在Android中旋转它的新资讯,同时我们还将为您解释计算触摸点的角度并在android中旋转它的位置的相关在本文中,我们将带你探索计算触摸点的角度并在An
在本文中,您将会了解到关于计算触摸点的角度并在Android中旋转它的新资讯,同时我们还将为您解释计算触摸点的角度并在android中旋转它的位置的相关在本文中,我们将带你探索计算触摸点的角度并在Android中旋转它的奥秘,分析计算触摸点的角度并在android中旋转它的位置的特点,并给出一些关于android – 在代码中旋转一个按钮(或里面的文本)、android – 如何在Canvas中旋转圆形动画、android – 当我们旋转手机时,如何在googlemap v2中旋转箭头、android – 旋转图像,并显示旋转角度的实用技巧。
本文目录一览:- 计算触摸点的角度并在Android中旋转它(计算触摸点的角度并在android中旋转它的位置)
- android – 在代码中旋转一个按钮(或里面的文本)
- android – 如何在Canvas中旋转圆形动画
- android – 当我们旋转手机时,如何在googlemap v2中旋转箭头
- android – 旋转图像,并显示旋转角度
计算触摸点的角度并在Android中旋转它(计算触摸点的角度并在android中旋转它的位置)
场景:我在SurfaceView上绘制圆形图像.用户触摸图像边框上的一个点并开始将其拖动到周围.我需要根据用户的移动旋转圆形图像.
我有两个重要的信息,图像中心X,Y坐标和触摸点坐标.
正如你在图像中看到的那样,用户触摸了一个点,根据我的绘制,触摸点角度应该在40左右.我无法正确计算它.
我尝试使用这个公式:
angle = Math.atan2(touchedY - centerY,touchedX - centerX) * 180 / Math.PI
我无法理解我应该如何计算角度,就像现在一样,它不能正常工作并且值不好.例如,在图像的情况下,角度计算是-50.
感谢您的时间,任何信息都很乐意.
LE:其实我认为我犯了一个错误,如下所述.圈子应该是这样的:
解决方法
现在我们可以回想起(或谷歌)
cos a = uv /(| u | * | v |)
其中a是向量和| u |之间的角度是矢量的长度.向上的u是(0,1),长度为1.
手动乘以向量会取消x项,并给我们这样的东西.
double tx = touch_x - center_x,ty = touch_y - center_y; double t_length = Math.sqrt(tx*tx + ty*ty); double a = Math.acos(ty / t_length);
注意如何通过从触摸点减去中心点来获得v向量.如果需要,请记得转换为学位.
android – 在代码中旋转一个按钮(或里面的文本)
我必须通过编码随机旋转一个按钮(或内部文本,它是相同的). API级别中的任何button.setRotate(x)是否低于11?
您可以使用旧动画框架旋转按钮,例如像这样:
Button button = (Button) findViewById(R.id.button);
// rotation from 0 to 90 degrees here
RotateAnimation a = new RotateAnimation(0,90);
a.setFillAfter(true);
a.setDuration(0);
button.startAnimation(a);
这里的问题是按钮看起来旋转,但无法正确单击.触发点击事件的坐标是按钮在旋转之前所在区域的坐标.
由于这不是一个非常好的解决方案,最好的办法是编写一个自定义视图,扩展Button类并在onDraw()中旋转按钮画布.在这种情况下,您还必须覆盖onMeasure().有关如何操作的信息,请参阅Custom Components.
除此之外,您可以尝试拦截按钮父布局中的单击事件,并在按钮当前坐标内发生单击时触发相应的事件.但这有点“hacky”.
android – 如何在Canvas中旋转圆形动画
用代码或示例可以帮助我非常感谢!
这是我在画布上绘制圆圈的代码:
import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Bundle; import android.view.View; public class AnimationActivity extends Activity { /** Called when the activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } public class SampleView extends View { public SampleView(Context context) { super(context); // Todo Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { Paint mPaint = new Paint(); mPaint.setStyle(Paint.Style.stroke); mPaint.setstrokeWidth(10); mPaint.setColor(Color.RED); canvas.drawCircle(75,75,mPaint); } } }
提前致谢!
解决方法
import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Bundle; import android.view.View; public class AnimationActivity extends Activity { public class SampleView extends View { Paint mPaint = new Paint(); private Animation anim; public SampleView(Context context) { super(context); mPaint.setStyle(Paint.Style.stroke); mPaint.setstrokeWidth(10); mPaint.setColor(Color.RED); } private void createAnimation(Canvas canvas) { anim = new RotateAnimation(0,360,getWidth()/2,getHeight()/2); anim.setRepeatMode(Animation.RESTART); anim.setRepeatCount(Animation.INFINITE); anim.setDuration(10000L); startAnimation(anim); } protected void onDraw(Canvas canvas) { int cx = getWidth()/2; // x-coordinate of center of the screen int cy = getHeight()/2; // y-coordinate of the center of the screen // Starts the animation to rotate the circle. if (anim == null) createAnimation(canvas) canvas.drawCircle(cx,cy,150,mPaint); // drawing the circle. } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } }
请享用!
android – 当我们旋转手机时,如何在googlemap v2中旋转箭头
任何人都可以帮我解决如何在谷歌地图v2中旋转箭头?你已经看到,在导航中箭头朝着我们面向的方向旋转.我想将它实现到我的应用程序.关于markerOption.rotation(旋转),我认为这似乎是一个静态的.我想在旋转手机时动态旋转箭头.
解决方法:
我能够做到这一点.它是如此容易.以下是如何.
这是读取传感器并获取手机的方向.
/**
* Initialize the sensor manager.
*/
private void setupSensorManager() {
mSensorManager = (SensorManager) mContext
.getSystemService(Context.SENSOR_SERVICE);
mSensorManager.registerListener(mSensorListener,
mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
SensorManager.SENSOR_DELAY_norMAL);
Log.d(TAG, "SensorManager setup");
}
/**
* The sensor event listener.
*/
SensorEventListener mSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
mOrientation = event.values[0];
Log.d(TAG, "Phone Moved "+mOrientation);
draw(mOrientation);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
这就是我真正旋转的地方.我的标记已添加到地图中.我从另一个班级访问它.
public void draw(float angle) {
// Take the relevant Marker from the marker list where available in map
AndroidMapGoogleOverlayItem myself = (AndroidMapGoogleOverlayItem) getoverlayItem(0);
if (myself == null) {
return;
}
myself.getMarker().setRotation(mOrientation); // set the orientation value returned from the senserManager
}
android – 旋转图像,并显示旋转角度
我在android中制作虚拟车速表.
我使用RotateAnimation()来旋转速度表针.
有没有办法在旋转过程中获得针的角度位置?也就是说,如果针从0度旋转到360度,我想在动画期间的每个点显示针角.
我使用以下代码来执行动画.
RotateAnimation rpmNeedleDeflection = new RotateAnimation(-32, 213, (float) 135, needle.getHeight()/2);
rpmNeedleDeflection.setDuration(1500);
rpmNeedleDeflection.setFillAfter(true);
needle.startAnimation(rpmNeedleDeflection);
needle.refreshDrawableState();
请帮忙…
提前致谢.
解决方法:
您可以尝试覆盖applyTransformation
RotateAnimation rpmNeedleDeflection = new RotateAnimation(fromdegrees, todegrees, ...){
protected void applyTransformation(float interpolatedTime,Transformation t) {
float currentDegree = fromdegrees+(todegrees-fromdegrees)*interpolatedTime;
super.applyTransformation(interpolatedTime, t);
};
}
关于计算触摸点的角度并在Android中旋转它和计算触摸点的角度并在android中旋转它的位置的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于android – 在代码中旋转一个按钮(或里面的文本)、android – 如何在Canvas中旋转圆形动画、android – 当我们旋转手机时,如何在googlemap v2中旋转箭头、android – 旋转图像,并显示旋转角度等相关知识的信息别忘了在本站进行查找喔。
本文标签: