圆形旋转onTouch
问题描述:
圆形旋转onTouch只有在点击一次后才起作用,它什么都不做。圆形旋转onTouch
这里是我的代码:
setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int n = 0;
postInvalidate();
for(int i=0; i<360; i++){
setRotationX(n + 1);
}
forceLayout();
我希望有人能帮助我。 我如何查看代码以便它可以多次运行?
答
如果使用goodm解决方案,您应该在您的清单中添加以下内容:
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true"/>
这是用于ICS和ICS之前的版本。
答
做动画,你需要创建在res文件夹中的文件夹“动画”,并添加这样一个XML文件:在您的Java类的尝试
<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"/>
:
Animation a = AnimationUtils.loadAnimation(this, R.anim.yourAnim);
a.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationEnd(Animation animation)
{
animPlaying = false;
}
@Override
public void onAnimationStart(Animation animation)
{
animPlaying = true;
}
@Override
public void onAnimationRepeat(Animation animation){}
});
public boolean onTouch(View v, MotionEvent event)
{
int n = 0;
postInvalidate();
if(aninmPlaying == false)
{
yourView.startAnimation(a);
}
forceLayout();
触摸后才开始动画并不容易吗? – goodm 2012-03-28 09:41:54
thanx的评论,但我怎么能让这样的动画? – user1297720 2012-03-28 09:49:38