2

I am developing an application wherein I need this download like functionality on the action bar of my activity.

I want to know is it some kind of a progress bar or a mere animation.

Thanks

Code:

drawable -> anim

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
      android:oneshot="false">
  <item android:drawable="@drawable/ic_action_download" android:duration="200" />
  <item android:drawable="@drawable/ic_action_holo_download" android:duration="200" />
</animation-list>

Activity

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater inflater = getMenuInflater();

    inflater.inflate(R.menu.activity_main, menu);
    return super.onCreateOptionsMenu(menu);
}

menu -> activity_main

 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android">

 <item 
    android:id="@+id/menu"
    android:icon="@drawable/anim"
    android:showAsAction="always"
    android:title="@string/xxx"
    android:visible="true" />

  </menu>

enter image description here

android developer
  • 1,253
  • 2
  • 13
  • 43

2 Answers2

0

One way of achieving this is by using the Animation-list drawable. Add the set of the different images to this xml file and it aimates according to the duration.

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true">
    <item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
    <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
    <item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>

Here is an SO answer that describes how to add it part of the notification tray.

Community
  • 1
  • 1
amalBit
  • 12,041
  • 6
  • 77
  • 94
0

Tip: If you want to supply custom layout animations, create a LayoutTransition object and supply it to the layout with the setLayoutTransition() method.

one example wil be available in http://developer.android.com/shareables/training/Animations.zip See the following files for the code implementation: src/LayoutChangesActivity.java layout/activity_layout_changes.xml menu/activity_layout_changes.xml In your activity's layout XML file, set the android:animateLayoutChanges attribute to true for the layout that you want to enable animations for. For instance:

<LinearLayout android:id="@+id/container"
    android:animateLayoutChanges="true"
    ...
/>

Now, all you need to do is add, remove, or update items in the layout and the items are animated automatically:

private ViewGroup mContainerView;
...
private void addItem() {
    View newView;
    ...
    mContainerView.addView(newView, 0);
}
Joe Sebin
  • 452
  • 4
  • 24