Jen*_*ala 66
API 11 为所有视图添加了setRotation()方法.
Pet*_*ete 58
您可以创建动画并将其应用于按钮视图.例如:
// Locate view
ImageView diskView = (ImageView) findViewById(R.id.imageView3);
// Create an animation instance
Animation an = new RotateAnimation(0.0f, 360.0f, pivotX, pivotY);
// Set the animation's parameters
an.setDuration(10000); // duration in ms
an.setRepeatCount(0); // -1 = infinite repeated
an.setRepeatMode(Animation.REVERSE); // reverses each repeat
an.setFillAfter(true); // keep rotation after animation
// Aply animation to image view
diskView.setAnimation(an);
Run Code Online (Sandbox Code Playgroud)
Ich*_*rus 46
扩展TextView类并覆盖该onDraw()方法.确保父视图足够大以处理旋转的按钮而不剪切它.
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.rotate(45,<appropriate x pivot value>,<appropriate y pivot value>);
super.onDraw(canvas);
canvas.restore();
}
Run Code Online (Sandbox Code Playgroud)
Rud*_*udi 26
我只是在我的代码中使用了简单的行,它的工作原理如下:
myCusstomView.setRotation(45);
Run Code Online (Sandbox Code Playgroud)
希望对你有效.
DYS*_*DYS 20
应用旋转动画(没有持续时间,因此没有动画效果)是比调用View.setRotation()或覆盖View.onDraw方法更简单的解决方案.
// substitude deltaDegrees for whatever you want
RotateAnimation rotate = new RotateAnimation(0f, deltaDegrees,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// prevents View from restoring to original direction.
rotate.setFillAfter(true);
someButton.startAnimation(rotate);
Run Code Online (Sandbox Code Playgroud)
小智 6
Joininig @Rudi和@ Pete的答案.我创建了一个RotateAnimation,它在旋转后也保持按钮功能.
setRotation()方法保留按钮功能.
代码示例:
Animation an = new RotateAnimation(0.0f, 180.0f, mainLayout.getWidth()/2, mainLayout.getHeight()/2);
an.setDuration(1000);
an.setRepeatCount(0);
an.setFillAfter(false); // DO NOT keep rotation after animation
an.setFillEnabled(true); // Make smooth ending of Animation
an.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
mainLayout.setRotation(180.0f); // Make instant rotation when Animation is finished
}
});
mainLayout.startAnimation(an);
Run Code Online (Sandbox Code Playgroud)
mainLayout是一个(LinearLayout)字段
| 归档时间: |
|
| 查看次数: |
112147 次 |
| 最近记录: |