android - Don't understand why OutOfMemory on setImageDrawable -


having problem custom button control have made. button defined in layout this:

<?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" >  <imageview     android:layout_width="180dp"     android:layout_height="180dp"     android:layout_centerinparent="true"     android:layout_margin="20dp"     android:background="#fff"     android:contentdescription="@string/my_button_info"     android:src="@drawable/button_appearance" />  </merge> 

and button_appearance defined this:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pic_down"   android:state_pressed="true" /> <item android:drawable="@drawable/button_pic"   android:state_focused="true" /> <item android:drawable="@drawable/button_pic" /> </selector> 

now, when push button (click on linearlayout) show different bitmap , animate rotating, here animation:

<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1666" android:fromdegrees="0" android:interpolator="@android:anim/linear_interpolator" android:pivotx="50%" android:pivoty="50%" android:repeatcount="infinite" android:todegrees="359" /> 

and call this:

public void animatebutton() {     mybutton.setenabled(false);     mybutton.setimagedrawable(getcontext().getresources().getdrawable(r.drawable.button_pic_spin));     mybutton.startanimation(animationutils.loadanimation(context, r.anim.spinner_animation)); } 

then, when action kicks off done stop it:

public void stopandenablebutton() {     mybutton.setenabled(true);     mybutton.setimagedrawable(getcontext().getresources().getdrawable(r.drawable.button_appearance));     ttcbutton.clearanimation(); } 

i've received few crashes crashlytics on line above call setimagedrawable. crashlytics says:

failed allocate 2869648 byte allocation 1275632 free bytes , 1245kb until oom

the weird thing pngs here 25k in size - , there 3 of them (2 referenced in button_appearance.xml , plain 1 button_pic_spin) how getting 2 megabytes requirement when try swap in ought 50k @ most?

is problem ought call clearanimation before setimagedrawable? system trying make bunch of allocations partially rotated bitmaps?

memory allocation images in android depend on pixels width , height of image. not disk size.

image memory size = width * height * 4 bytes (byte red, byte green, byte blue , byte alpha)


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -