views:

132

answers:

1

I'm looking to make an ImageButton that contains an animation drawable, more precisely the repetitive tweened animation of a progressbar spinner (like the view/widget that exists for this).

In xml I specified this for the ImageButton in the activity's layout:

<ImageButton android:id="@+id/i_back_cover" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:scaleType="centerInside" 
    android:gravity="center" android:layout_weight="1" android:adjustViewBounds="true" 
    android:src="@anim/progress_large"> 
</ImageButton>

The "progress_large" animation is in res/anim/:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <rotate
        android:drawable="@drawable/spinner_black_76"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromDegrees="0"
        android:toDegrees="350"
        android:duration="1200" />
</set>

I set toDegrees to 350 for now, to make sure it would rotate. spinner_black_76 is just an image.

When I open the activity having this layout, the app crashes before displaying.

Weird, there's no actual stacktrace in the log, just a killed VM if I'm right (I hardly can believe this myself):

10-07 21:16:18.467: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.EDIT dat=content://net.lp.collectionista.products/items/book/1 cmp=net.lp.collectionista/.ui.activities.items.book.BookItemEditWindow }
10-07 21:16:18.687: DEBUG/AndroidRuntime(636): Shutting down VM
10-07 21:16:18.687: WARN/dalvikvm(636): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-07 21:16:18.687: DEBUG/FlurryAgent(636): Ending session
10-07 21:16:18.977: DEBUG/dalvikvm(636): GC_FOR_MALLOC freed 3876 objects / 597200 bytes in 98ms
10-07 21:16:19.007: WARN/ActivityManager(59):   Force finishing activity net.lp.collectionista/.ui.activities.items.book.BookItemEditWindow
10-07 21:16:19.016: WARN/ActivityManager(59):   Force finishing activity net.lp.collectionista/.ui.activities.collections.book.BookCollectionViewWindow
10-07 21:16:19.507: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{43fec528 net.lp.collectionista/.ui.activities.items.book.BookItemEditWindow}
10-07 21:16:21.437: INFO/Process(636): Sending signal. PID: 636 SIG: 9
10-07 21:16:21.487: INFO/ActivityManager(59): Process net.lp.collectionista (pid 636) has died.
10-07 21:16:21.517: INFO/WindowManager(59): WIN DEATH: Window{4400f330 net.lp.collectionista/net.lp.collectionista.ui.activities.CollectionsListWindow paused=false}
10-07 21:16:21.517: INFO/WindowManager(59): WIN DEATH: Window{43fc89d0 net.lp.collectionista/net.lp.collectionista.ui.activities.collections.book.BookCollectionViewWindow paused=true}
10-07 21:16:21.667: INFO/UsageStats(59): Unexpected resume of com.android.launcher while already resumed in net.lp.collectionista
10-07 21:16:21.727: WARN/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 636 uid 10034
10-07 21:16:27.237: DEBUG/dalvikvm(278): GC_EXPLICIT freed 32 objects / 1616 bytes in 81ms
10-07 21:18:14.047: DEBUG/AndroidRuntime(654): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<

What am I doing wrong in this case? Or what would be a better way to get a progressbar round spinner on top of a button?

+1  A: 

:: smacks forehead ::

I should have realized this before starting in on the comments.

I'm looking to make an ImageButton that contains an animation drawable, more precisely the repetitive tweened animation of a progressbar spinner (like the view/widget that exists for this).

That isn't an AnimationDrawable. An AnimationDrawable is a frame animation, not a tweened one. As the documentation for your animation XML indicates:

compiled resource datatype: Resource pointer to an Animation.

whereas for a frame animation:

compiled resource datatype: Resource pointer to an AnimationDrawable.

Hence, I don't think you can do what you're trying to do the way you're trying to do it. You could use a frame animation and use a handful of hand-rotated versions of your graphic.

CommonsWare
You're right. A tweened animation is not a Drawable and therefore I shouldn't put it in the `android:src` tag. The fact that it's in res/anim also should have given it away. My mistake. The funny thing is that making a spinning progressbar yourself is not such an easy thing to do, if you compare it with the effortless native ProgressBar xml code. The easiest way to do it yourself is then probably to make the frame animation out of 12 items, which are statically in-xml rotated drawables. Thanks
pjv
Actually, it seems the ImageButton expects to hold a BitmapDrawable (and somehow does not complain when it does not get that from the xml). So the frame animation AnimationDrawable idea I described above also will not work. Gonna have to try a .gif.
pjv
@pjv: Guaranteed that a GIF won't work on 2.1 and below. Might work on 2.2 -- I know some animated GIF support was added, but I'm not sure exactly where. You could also try an `ImageView` floating over a caption-less `Button`, where the `ImageView` passes the click event onto the `Button`.
CommonsWare