我有ImageView
一个RelativeLayout
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#272727"
android:orientation="horizontal" >
<ImageView
android:id="@+id/logoMobile"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:paddingTop="2.2dp"
android:src="@drawable/logo" />
<ImageButton
android:id="@+id/BtnSlide"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:background="@null"
android:src="@drawable/lin" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/BtnSlide"
android:gravity="center"
android:paddingLeft="30dp"
android:text="HEADER"
android:textAppearance="?android:attr/textAppearanceMedium" />
这个 xml 在应用程序的顶部定义了一个“标签栏”,就在通知栏的下方。我想要ImageView
围绕它的中心旋转。我在我的方法中尝试过这种方式onCreate
:
logo = (ImageView)findViewById(R.id.logoMobile);
ApplyAnimationToObject doAnimation = new ApplyAnimationToObject(logo);
doAnimation.startRotationAnimation();
然后ApplyAnimationToObject
上课:
package Logic;
public class ApplyAnimationToObject {
final ImageView image;
public ApplyAnimationToObject(ImageView image) {
this.image = image;
}
public void startRotationAnimation() {
RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(7000);
image.startAnimation(anim);
}
}
但是 ImageView 根本不会旋转或有任何动画。谁能帮我吗?
编辑
我尝试使用此代码:
public void rotateView(View v){
Animation rotateAnimation = new RotateAnimation(0,
360, v.getWidth() / 2, v.getWidth() / 2);
rotateAnimation.setDuration(10000);
v.startAnimation(rotateAnimation);
if(rotateAnimation.hasEnded())
Log.i("+++++ANIMATION+++++", "ENDED!!");
else
Log.i("+++++++ANIMATION++++++", "NOT ENDED");
}
并且输出 tilLogCat
告诉我动画还没有结束,但是没有动画到ImageView