简体   繁体   English

卫星菜单:动画只能播放一次

[英]Satellite menu: Animation works only once

I'm using the Sattelite Menu in my android app. 我在我的Android应用程序中使用了Sattelite菜单

I've included it as my project, added the following XML and Java and the app works just fine, no errors. 我将其包含在我的项目中,添加了以下XML和Java,该应用程序运行正常,没有错误。

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sat="http://schemas.android.com/apk/res/android.view.ext"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <android.view.ext.SatelliteMenu
        android:id="@+id/menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left" 
        android:layout_margin="8dp"
        sat:satelliteDistance="170dp"
        sat:mainImage="@drawable/ic_launcher"
        sat:totalSpacingDegree="90"
        sat:closeOnClick="true"
        sat:expandDuration="500"/>

</FrameLayout>

and Java: 和Java:

SatelliteMenu menu = (SatelliteMenu) findViewById(R.id.menu);
    List<SatelliteMenuItem> items = new ArrayList<SatelliteMenuItem>();
    items.add(new SatelliteMenuItem(3, R.drawable.ic_launcher));
    items.add(new SatelliteMenuItem(2, R.drawable.ic_launcher));
    items.add(new SatelliteMenuItem(1, R.drawable.ic_launcher));

The app starts, with the little menu icon in the bottom left corner, as expected. 该应用程序将启动,并按预期在左下角显示小菜单图标。 Click it and little buttons pop out with a fancy animation. 单击它,弹出带有精美动画的小按钮。 Click it again, the menu closes and the buttons go back with another fancy animation. 再次单击它,菜单关闭,按钮又返回另一个精美的动画。

The Problem begins.. Now, when I click it again (3rd time), there is no animation this time. 问题开始了。现在,当我再次单击它(第三次)时,这次没有动画。 The buttons simply appear in their correct places (and still work) but they don't fly out. 这些按钮仅显示在其正确的位置(并且仍可以使用),但不会飞出。 For some reason the animation does not gets started. 由于某些原因,动画无法开始。

I've tried to look at the source and this should not be happening. 我试图查看源代码,这应该不会发生。 Even the sample app works perfect. 甚至示例应用程序也可以完美运行。 But when I implemented it in my own app, the animation just works the first time when I open the menu. 但是,当我在自己的应用程序中实现该动画时,该动画仅在我打开菜单时第一次起作用。

What could be causing this? 是什么原因造成的?

Thank you! 谢谢!

EDIT: This solution too doesn't work. 编辑:此解决方案也行不通。 It didn't do anything :/ 它什么也没做:/

private void onClick() {
    if (plusAnimationActive.compareAndSet(false, true)) {
        if (!rotated) {
            resetItems();
            imgMain.startAnimation(mainRotateLeft);
            for (SatelliteMenuItem item : menuItems) {
                item.getView().startAnimation(item.getOutAnimation());
            }
        } else {
            resetItems();
            imgMain.startAnimation(mainRotateRight);
            for (SatelliteMenuItem item : menuItems) {
                item.getView().startAnimation(item.getInAnimation());
            }
        }
        rotated = !rotated;
    }
}

Layout Animations are run when views are added to the layout. 将视图添加到布局时,将运行布局动画。 So you will have to manually add/remove the views on every expand/collapse for the layout animation to work. 因此,您必须在每次展开/折叠时手动添加/删除视图,布局动画才能起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM