When you long click on email item in Gmail
application (Honeycomb
) the context-like menu is shown with it's items animated on start. How this is made? Thanks.
You cannot animate MenuItems, so the trick is to set a same looking View in its place with MenuItem.setActionView() and animate that view as you would normally and then unset it when animation is done with 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 for 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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With