Hello, everyone. I'v stucked with a problem of creating of
AnimationDrawable object not using xml file, but from assets. Here is
my Activity code:
package org.example.Animation;
import java.io.IOException;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
private LinearLayout ll;
private ImageView image;
private AnimationDrawable ad;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ll = new LinearLayout(this);
LinearLayout.LayoutParams lp = new
LinearLayout.LayoutParams(-2, -2);
image = new ImageView(this);
ll.addView(image, lp);
setContentView(ll);
AssetManager am = getAssets();
ad = new AnimationDrawable();
StringBuilder sb= new StringBuilder("loader/loader-");
// Fetching frames from assets
for(int i = 1; i < 11; i++) {
sb.append(i);
sb.append(".png");
Log.d("DownloadImageTask", "Fetching image: " +
sb.toString());
try {
Drawable d =
Drawable.createFromStream(am.open(sb.toString()), null);
ad.addFrame(d,
500);
}
catch (IOException e) {
Log.d("ImageViewAdapter", "IOException: " +
e.getMessage());
}
sb.delete(14, sb.length()); // 14 - is the index of first
digit of frame
}
image.setBackgroundDrawable(ad);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
ad.start();
}
}
I need to start animation immediately after window gets focus, but
there is nothing to be displayed on the screen.
I was looking for a source of this problem and found this:
http://code.google.com/p/android/issues/detail?id=14863
As I understand correctly, the problem is that I set layout parameters
of the ImageView to WRAP_CONTENT (-2) and to get expectale behavior I
just need to make them either fixed or FILL_PARENT, but after I do
that there is no positive effect.
Tell me please, what am I doing wrong? And please take into
consideration, that my main goal is to avoid using of R.java file in
my appplication, although it's loooked strange. That's why I use
assets instead.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en