Animating menu items in ActionBar

When you long click on an email item in the application Gmail( Honeycomb), the items animated at startup are displayed in the context menu. How it's done? Thank.

+5
source share
3 answers

Take a look here . You can animate any view causing the animation to start with it.

-1
source

MenuItems, , MenuItem.setActionView() , , , MenuItem.setActionView(null)

public class MainFragment extends Fragment {

   private Menu mOptionsMenu;

   @Override
   public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
       mOptionsMenu = menu;
       inflater.inflate(R.menu.fragment_main, menu);
   }

   private void animateActionBarItem() {
       final MenuItem refreshItem = mOptionsMenu.findItem(R.id.action_refresh);
       refreshItem.setActionView(R.layout.actionbar_foo);
       refreshItem.getActionView()
            .animate()
            .setInterpolator(new AccelerateInterpolator())
            .setDuration(100L)
            .scaleX(2F)
            .scaleY(2F)
            .withEndAction(new Runnable() {

                @Override
                public void run() {
                    refreshItem.setActionView(null);
                }
            });
      }

}

XML R.layout.actionbar_foo

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/actionButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_action_accept" />
0

Take a look at my answer here . This is due to changes in the layout of the parent menu item, but if you look at my idea, you will understand how to animate the menu items.

0
source

All Articles