【问题标题】:ImageView with rotate xml not rotating带有旋转xml的ImageView不旋转
【发布时间】:2015-11-17 06:38:15
【问题描述】:

我正在使用以下代码,

<ImageView
        android:id="@+id/imgView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/animate"/>

我的 animate.xml 是,

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromDegrees="90"
    android:toDegrees="90"
    android:repeatCount="infinite"
    android:drawable="@drawable/cameras">

在java中启动它,

ImageView imgView=(ImageView)findViewById(R.id.imgView);
              Animation rotation = AnimationUtils.loadAnimation(this, R.drawable.animate);
              imgView.startAnimation(rotation);

但我的 ImageView 仍然没有旋转, 我见过很多例子,但没有一个是有效的。

【问题讨论】:

    标签: android xml


    【解决方案1】:

    试试这个

        <ImageView
        android:id="@+id/imgView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/animate"/>
    
      <?xml version="1.0" encoding="utf-8"?>
      <rotate xmlns:android="http://schemas.android.com/apk/res/android"
       android:fromDegrees="0"
       android:interpolator="@android:anim/linear_interpolator"
       android:pivotX="50%"
       android:pivotY="50%"
       android:repeatCount="infinite"
       android:toDegrees="359"
       android:duration="1000" >
     </rotate>
    
      ImageView imgView=(ImageView)findViewById(R.id.imgView);
              Animation rotation = AnimationUtils.loadAnimation(this,  R.drawable.animate);
              imgView.startAnimation(rotation);
    

    【讨论】:

      【解决方案2】:

      尝试在您的 xml 动画中执行此操作

      <?xml version="1.0" encoding="utf-8"?>
      <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:shareInterpolator="false" >
      
      <rotate
          android:interpolator="@android:anim/linear_interpolator"
          android:duration="2500"<!-- put any duration you want -->
          android:pivotX="50%"
          android:pivotY="50%"
          android:repeatCount="infinite"
          android:repeatMode="restart"
          android:toDegrees="360" />
      
      </set>
      

      【讨论】:

        【解决方案3】:

        试试这个

        <?xml version="1.0" encoding="utf-8"?>
            <set xmlns:android="http://schemas.android.com/apk/res/android"
                android:shareInterpolator="false" >
        
                <rotate
                    android:duration="4000"
                    android:interpolator="@android:anim/linear_interpolator"
                    android:pivotX="50%"
                    android:pivotY="50%"
                    android:repeatCount="infinite"
                    android:repeatMode="restart"
                    android:toDegrees="360" />
        
            </set>
        

        【讨论】:

          【解决方案4】:

          看起来有两件事会导致这个问题:

          1. AnimationUtils.loadAnimation(this, R.drawable.animate); animate.xml 不应该是动画文件夹中的动画资源而不是可绘制对象吗?
          2. 您正在从 90 度旋转到 90 度。也许这只是没有做任何事情。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-09-15
            • 2021-05-18
            • 2018-02-03
            相关资源
            最近更新 更多