I am writing a simple Widget application for Android, In my Widget I Layout I have ImageViewRefresh
control on which I have set Refresh Image Picture (Green Image Below).
At some point I press on a ImageViewRefresh
button in my Widget and application start to download some content from the Internet, while application downloading data in a background I want to make some animation, like rotate my image (Green Image Below). Can I do that ?
I have read some posts about Image animation, but I can find only animation of .gif pictures in application, is where a way to rotate image for example make some rotated images and change them or something else.
Here is a part of code from my layout
my image is not rotating. Why ? (my image is simple .png image)
<ProgressBar
android:id="@+id/progressBarRefresh"
android:layout_width="36dp"
android:indeterminateDrawable="@drawable/arrow_refresh"
android:layout_height="36dp"
android:layout_alignTop="@+id/imageViewArrowNext"
android:layout_marginRight="70dp"
android:layout_toLeftOf="@+id/textViewAutherName"
android:indeterminate="true" />
Image which I want to rotate.
You can upload multiple PNG or JPG images to our animated PNG maker, choose the order, frame duration and transition effect (if you want to), and it will assemble animated PNG from these images. With this method you can use the full potential of animated PNG and create images with much broader color palette than GIFs.
In After Effects go to File → Import → File or double-click in the Project Window to open up the Import Window. Locate the PNG image sequence you wish to use, select the first image, and be sure to check the box for Sequence. *Make sure the import settings are set to import as Footage.
After creating your animation, go to Export > Export Movie and select “PNG Sequence” from the dropdown menu. The process in Photoshop is very similar. Go to File > Export > Render Video. In the Render Video pane, select “Photoshop Image Sequence” from the dropdown and choose PNG as the format.
edit: I'll apologise in advance but I believe my answer might have mislead from the question:
original post:
Do not try to animate the widget yourself
Use a ProgressBar
set it to be indeterminate and use setIndeterminateDrawable(Drawable d);
to set the image you want to be rotating. (or just leave the native one that looks very nice too)
edit: here's what the code would look like:
// in your widget update method:
View v = LayoutInflater.from(context).inflate(R.layout.widget, null);
ProgressBar pb = (ProgressBar) v.findViewById(R.id.progressBar1);
pb.setIndeterminateDrawable(R.drawable.widget_processing);
here's what the XML for something like this would look like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignLeft="@+id/textView1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:indeterminate="true" />
</RelativeLayout>
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