I am trying to achieve adding the animated gifs into my application.
1- I am able to download the animated gif from server. 2- I am able to decode the animated gif (using my custom decoder) and have a separate Bitmap corresponding to its frames.
Now I want to animate it using the frame by frame animation. As i read, to perform the frame by frame animation the first thing that is required is "animation-list".
I want to know how i can create the required "animation-list" programatically containing each Bitmap as a separate frame.
You can use AnimationDrawable similiar to http://androidforums.com/application-development/11620-programmatic-frame-frame-animation-examle-animationdrawable.html but use your own files instead of taken from resources.
Note that you have to be careful about density of screen and bitmaps which are downloaded rather than taken from resources otherwise it might look differently on different screen sizes/resolutions. More about it here: http://developer.android.com/guide/practices/screens_support.html see particularly "Scaling Bitmap Objects created at runtime" chapter
It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus
Related
Given:
A number of images (10 - 15) residing in assets folder (as practice shows, the better approach is to keep high-resolution images in assets)
Android UI thread (caching drawables in advance is already made in a background thread)
The issue:
Need to display all the images one on another smoothly and not blocking UI thread after the images are drawn.
Already used approaches:
Dynamically create a required number of ImageView and then call .setImageDrawable(). This takes a lot of time but the worst thing is that the UI thread is being blocked even after all the images are drawn on their ImageView.
Create a LayerDrawable object and pass as argument an array of the required Drawables. Then put it on an ImageView also by calling .setImageDrawable(). This option behaves the same like the one described above.
Is there a way to solve this issue? Or Android devices not capable to cope with it?
Try Picasso library:
http://square.github.io/picasso/
It has support for resources:
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);
Picasso.with(context).load(new File(...)).into(imageView3);
If you are requiring a smooth transition between images, please try viewFlipper
https://developer.android.com/reference/android/widget/ViewFlipper.html
Basically you can add imageView inside the viewflipper and start animation to move from previous to next image. I am not sure if you need user interactions like scrolling or not. You can try viewPager if user need to scroll betweens images.
Please note that Glide does provide some transition effects for switching between placeholder and image to display. But transition between images are not included, you can have a look here
http://bumptech.github.io/glide/doc/transitions.html
I hope this helps because i am not sured that if you are asking the transition between images or rendering images.
I need some help,
I am creating an app, and want it to run faster I mean when the app is started first it shows a blank white screen for o 1-2 seconds and then loads images. I have a layout background image, and 4 imageviews which are clickable and take you to the next activity. I read somewhere i should use threads to load images and it will load them on a separate thread faster, but i have some problem using it.
So here are the problems and android studio explanations:
Thread thread=new Thread(
public void run(){
ImageView tipka=(ImageView)findViewById(R.id.tipkaproba);
tipka.setImageResource(R.drawable.instructions);
LinearLayout asd=(LinearLayout)findViewById(R.id.layoutproba);
asd.setBackgroundResource(R.drawable.backfround123);
}
).start();
Now the android studio says:
After
"Thread(" )expected
Before
"public void run(){"
; expected
On ").start();"
Invalid method declaration; return type required, Missing method body, or declare abstract.
Now i would like to know:
Does this speed up loading images, ( if not how to do it then)
How to fix my errors.
Thanks anyway !
Do all images fit in the screen?! If users need to scroll to view other images why load all of them at once? Use a grid view with adapter to load the image. In this way when the app start only images on the screen will be loaded and then when the user scrolls other images show up!
another thing you can do is to have 2 version of each image. one low quality with small size that loads first and one for high quality image. that will load latter. You can also calculate the base color for each image (use open source code or do it manually). then set the background image of iamgeview to this color. So when the image finally loads on the screen. The difference is not as dramatic as it was before.
If you want to use thread try AsyncTask first. Using AsyncTask is simpler than defining thread yourself.
Try to decrease the size of your images! If you be able to do this. it works better than any other trick! It's mobile, you don't have to show supper high quality images. users don't even notice most of the time
You probably took care of this but it worth mentioning that you need to provide different images for different screen densities and it's critical for performance as well as quality.
I want to create a custom, complicated loading graphic for my Android App (minSDK 8).
If I create a GIF with 100 frames, is there a way in Java/Android to tell it which frame to go to during my 'doProgress()' function?
Is there another or better way to do custom loading graphics?
If I create a GIF with 100 frames, is there a way in Java/Android to tell it which frame to go to during my 'doProgress()' function?
Since Android does not do animated GIFs, no.
Is there another or better way to do custom loading graphics?
Option #1: Use a frame animation.
Option #2: Use a RotateAnimation with a single image in an ImageView.
Option #3: Use ViewPropertyAnimator (using NineOldAndroids for the backport) to animate android:rotation with a single image in an ImageView.
There may be other options as well, though those are the three that come to mind.
If you have a gif image, then you can use WebView component to show the gif image. In webview, the image loops itself, we do not need to do extra work.
I'm creating a 2d game and i'm using a class with static Texture elements for accessing them from everywhere.Now i want to load my assets asynchronously because i want to show a progress bar with a loading screen.How can i perform this?
Take a look at AsyncTask.
In fact, Google published an article almost exactly what you are trying to do: loading an image in background and display a progress bar while the image is being loaded. The different is, while your code will load stuffs from app resource, the code in google article loads images from network. However, it should point you to the right direction.
See the article at https://sites.google.com/site/androidhowto/how-to-1/create-a-custom-progress-bar-using-asynctask
Note that the code in that article doesn't handle screen rotation well. The problem is, by default, when the screen is rotated, the original is destroyed and the new one is created. If your AsyncTask keeps the any reference to the original one (for example, the one that point to the progress bar object), then it becomes dangling. However, since your app is a game I assume its orientation is fixed, so you might not have to worry about it.
I have my app working where it comes to a screen with 6 thumbnails. The user will select one and the next screen is a full image. I've accomplished this through an OnClickListener to call a new activity/xml (I'm new at this, sorry if my terminology is a little off).
My question is: is there a way to avoid creating 6 activty/xml (one for each thumbnail)? ultimately, my app will have about 40 thumbnails that can be selected for full screen view.
I've been trying to follow examples online where it appears that the code is presenting the full image within java instead of referencing an xml file. I've also seen use of Bitmap and BitmapFactory. Is this the way to go?
If the full screen image can be created dynamically within java, will the Back button still work to the user back to the screen with 6 thumbnails?
thanks, J
The simplest approach to take is to pass a reference to the image in the intent you use to launch the full-screen activity.
You can use the BitmapFactory to create a Bitmap, and then update the ImageView (or however you're displaying the image) from the loaded bitmap.
Using this approach, the back button will still work normally, but you'll only need one activity to display the full-screen image.