animationRunning 安卓
时间: 2023-05-23 15:07:17 浏览: 36
平台下如何启动动画?
在安卓平台下启动动画一般可以通过以下步骤:
1. 在 res 目录下创建一个 anim 目录,然后在该目录下创建一个动画文件(XML 格式),如:anim/sample_animation.xml。
2. 在 layout 文件中添加一个对应的 ImageView 控件。
3. 在 activity 中获取该 ImageView 的实例,并使用 AnimationUtils 类的 loadAnimation() 方法加载该动画。
4. 调用 ImageView 的 startAnimation() 方法启动动画。
示例代码如下:
XML 文件 anim/sample_animation.xml:
```xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000" />
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:duration="2000"
android:pivotX="50%"
android:pivotY="50%" />
</set>
```
布局文件 layout/sample_layout.xml:
```xml
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sample_image" />
```
Java 代码:
```java
ImageView imageView = findViewById(R.id.imageView);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.sample_animation);
imageView.startAnimation(animation);
```