blo*_*ork 29 animation android android-widget
I have a widget which starts an activity when it is clicked. I'd like to have some kind of fancy animation to display this activity, rather than the standard scroll-from-right of Android. I'm having problems setting it, though. This is what I have:
slide_top_to_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromYDelta="-100%" android:toXDelta="0" android:duration="100" />
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="50" />
</set>
Run Code Online (Sandbox Code Playgroud)
...在anim.xml中引用
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="50%"
android:animation="@anim/slide_top_to_bottom" />
Run Code Online (Sandbox Code Playgroud)
但那我从哪里参考呢?我已经尝试了我要插入的活动的基本元素,以及清单中的activitiy条目,两次都是
android:layoutAnimation="@+anim/anim"
Run Code Online (Sandbox Code Playgroud)
我可能做错了.任何帮助深表感谢!
Ako*_* Cz 52
您可以创建一个自定义主题,并引用您自己的动画,并将其应用于清单文件中的Activity.我成功地使用以下样式定义为浮动窗口应用自定义动画.如果将样式的父级设置为"@android:style/Animation.Activity",则可以执行类似的操作.
查看以下文件,了解有关可覆盖内容的更多详细信息.
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values /themes.xml
这是我的styles.xml和manifest.xml的一部分
styles.xml
<style name="MyTheme" parent="@android:style/Theme.Panel">
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">@style/MyAnimation.Window</item>
</style>
<!-- Animations -->
<style name="MyAnimation" />
<!-- Animations for a non-full-screen window or activity. -->
<style name="MyAnimation.Window" parent="@android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/grow_from_middle</item>
<item name="android:windowExitAnimation">@anim/shrink_to_middle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
的Manifest.xml
<activity
android:name="com.me.activity.MyActivity"
android:label="@string/display_name"
android:theme="@style/MyTheme">
</activity>
Run Code Online (Sandbox Code Playgroud)
startActivity(intent);
overridePendingTransition(R.anim.slide_top_to_bottom, R.anim.hold);
Run Code Online (Sandbox Code Playgroud)
检查此链接:overridePendingTransition方法
编辑:
实现视图的动画.你已经使用了如下的startAnimation方法
view.startAnimation(AnimationUtils.loadAnimation(
WidgetActivity.this,R.anim.slide_top_to_bottom));
Run Code Online (Sandbox Code Playgroud)
检查此链接: