خرید بک لینک

Vote count: 0

I'm trying to animate a 'MenuItem' when I add it to the actionbar. The problem is that I have to call 'MenuItem.visible(true)' before I load the animation or nothing happens at all. I have an animation listener and I tried putting it in 'onStartAnimation()' but that doesn't get called if I only put it there. Also, if I add 'MenuItem.setActionView(null)' in 'onAnimationEnd()', then all menu items flash quickly, which doesn't look nice. This is how I am animating it:

public static void menuItemRefreshEntry(){
    new Handler(Looper.getMainLooper()).post(new Ruable(){
            @Override
            public void run(){
                //Load the action view
                LayoutInflater inflater = (LayoutInflater) HotspotHelper.getAppContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                ImageView iv = (ImageView) inflater.inflate(R.layout.action_view_refresh, null);

                //Get the menu item
                final MenuItem menuItem = menu.findItem(R.id.action_refresh);
                //menuItem.setVisible(true); //TODO: animation never starts if this is not here

                //Load the animation
                Animation animation = AnimationUtils.loadAnimation(HotspotHelper.getAppContext(), R.anim.fade_in);
                animation.setAnimationListener(new Animation.AnimationListener(){

                        @Override
                        public void onAnimationStart(Animation p1)
                        {
                            // TODO: Implement this method
                            Toast.makeText(HotspotHelper.getAppContext(), "start", Toast.LENGTH_SHORT).show();
                            //visibility not working here
                            menuItem.setVisible(true);
                        }

                        @Override
                        public void onAnimationEnd(Animation p1)
                        {
                            //menu.findItem(R.id.action_refresh).setActionView(null);
                            menuItem.setActionView(null);
                            Toast.makeText(HotspotHelper.getAppContext(), "end", Toast.LENGTH_SHORT).show();
                            //menuItem.setVisible(false);
                        }

                        @Override
                        public void onAnimationRepeat(Animation p1)
                        {
                            // TODO: Implement this method
                        }


                    });

                //Apply the action view and animation
                iv.startAnimation(animation);
                menuItem.setActionView(iv);

            }
        });

asked 41 secs ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 11 خرداد 1395 ساعت: 0:27

صفحه بندی