有没有办法在层列表定义中为我的应用程序项目设置动画(旋转)?
Is there a way to animate (rotating) my application item within a layer-list definition?
目前我有以下可绘制对象 (splash.xml
) 定义:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/grey_300"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
我通过如下定义 activity 将其用于初始屏幕:
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
该样式来自styles.xml
:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
,我想知道我是否可以为屏幕上居中的徽标制作动画(也许旋转它)。达到目标的最佳方式是什么?我已经尝试在 item
元素中使用 animated-rotate
进行一些尝试,但直到现在才成功。
也许这会有所帮助:
我注意到您使用了 this 指南。然而,有人在评论中问他是否可以为他的启动画面添加动画,他的回答是:
It's not possible to do an animation with the splash screen pattern that I've listed above. The animation would only be available when the app has already loaded.
Outside of this, you can animate a layer list. Just apply it as the background on some view and animate that view.
我 运行 遇到了同样的问题并使用了解决方法。我创建了一个没有布局的 SplashActivity 和一个带有 ProgressBar 布局的 ProgressActivity,并使用 Intents 从 SplashActivity 到 ProgressActivity 以及从 ProgressActivity 到 MainActivity。下面的一些代码。感谢以下 YouTube 视频在 xml 中设置 ProgressBar:https://www.youtube.com/watch?annotation_id=annotation_1961654299&feature=iv&src_vid=yJ3cP6r8cxU&v=Ok30rN5SUe8
SplashTheme 的可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#EEEEEE"/>
</item>
<item android:id="@android:id/background">
<shape
android:shape="ring"
android:innerRadiusRatio="24"
android:thickness="18dp"
android:useLevel="false">
<solid android:color="#EF9A9A"/>
</shape>
</item>
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="0"
android:toDegrees="360">
<shape
android:shape="ring"
android:innerRadiusRatio="24"
android:thickness="18dp"
android:useLevel="false">
<gradient
android:color="@android:color/transparent"
android:angle="0"
android:startColor="#D50000"
android:type="sweep"
android:useLevel="false"/>
</shape>
</rotate>
</item>
</layer-list>
ProgressBar 的可绘制对象:与上面相同,但从两个形状中删除了 innerRadiusRatio 和厚度。
内容进度xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="nl.braaks55.minesweeper.activities.Progress"
tools:showIn="@layout/activity_progress">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ProgressBar
android:layout_width="160dp"
android:layout_height="160dp"
style="?android:attr/progressBarStyleLarge"
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/progress_bar"
android:max="100"
android:progress="20"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/loading"
android:textAppearance="?android:textAppearanceLarge" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
飞溅活动:
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, ProgressActivity.class);
startActivity(intent);
finish();
}
}
进度活动:
public class ProgressActivity extends AppCompatActivity {
private static final long DELAY = 3000L;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent(ProgressActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, DELAY);
}
}
目前我有以下可绘制对象 (splash.xml
) 定义:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/grey_300"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
我通过如下定义 activity 将其用于初始屏幕:
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
该样式来自styles.xml
:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
,我想知道我是否可以为屏幕上居中的徽标制作动画(也许旋转它)。达到目标的最佳方式是什么?我已经尝试在 item
元素中使用 animated-rotate
进行一些尝试,但直到现在才成功。
也许这会有所帮助:
我注意到您使用了 this 指南。然而,有人在评论中问他是否可以为他的启动画面添加动画,他的回答是:
It's not possible to do an animation with the splash screen pattern that I've listed above. The animation would only be available when the app has already loaded.
Outside of this, you can animate a layer list. Just apply it as the background on some view and animate that view.
我 运行 遇到了同样的问题并使用了解决方法。我创建了一个没有布局的 SplashActivity 和一个带有 ProgressBar 布局的 ProgressActivity,并使用 Intents 从 SplashActivity 到 ProgressActivity 以及从 ProgressActivity 到 MainActivity。下面的一些代码。感谢以下 YouTube 视频在 xml 中设置 ProgressBar:https://www.youtube.com/watch?annotation_id=annotation_1961654299&feature=iv&src_vid=yJ3cP6r8cxU&v=Ok30rN5SUe8
SplashTheme 的可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#EEEEEE"/>
</item>
<item android:id="@android:id/background">
<shape
android:shape="ring"
android:innerRadiusRatio="24"
android:thickness="18dp"
android:useLevel="false">
<solid android:color="#EF9A9A"/>
</shape>
</item>
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="0"
android:toDegrees="360">
<shape
android:shape="ring"
android:innerRadiusRatio="24"
android:thickness="18dp"
android:useLevel="false">
<gradient
android:color="@android:color/transparent"
android:angle="0"
android:startColor="#D50000"
android:type="sweep"
android:useLevel="false"/>
</shape>
</rotate>
</item>
</layer-list>
ProgressBar 的可绘制对象:与上面相同,但从两个形状中删除了 innerRadiusRatio 和厚度。
内容进度xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="nl.braaks55.minesweeper.activities.Progress"
tools:showIn="@layout/activity_progress">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ProgressBar
android:layout_width="160dp"
android:layout_height="160dp"
style="?android:attr/progressBarStyleLarge"
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/progress_bar"
android:max="100"
android:progress="20"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/loading"
android:textAppearance="?android:textAppearanceLarge" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
飞溅活动:
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, ProgressActivity.class);
startActivity(intent);
finish();
}
}
进度活动:
public class ProgressActivity extends AppCompatActivity {
private static final long DELAY = 3000L;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent(ProgressActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, DELAY);
}
}