In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In order to solve the problem of how to make Gif animation move in Android development, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
We have successively launched a number of Android development tutorials, "how to achieve TCP and UDP transfer" and "Android UI" Design official tutorials. This article will explain the tutorials for Gif picture playback in Android. It is not supported to play frame animation directly with Gif images in Android. The following animation cannot be played in Android:
Android provides another solution, which is to use the AnimationDrawable function to make it support frame-by-frame playback, but how to break up the gif picture into a picture of each frame? Here are two good software that can help us break up the pictures.
Gifsplitter2.0
Download address: gif partition
The method of use is as follows:
This software divides the pictures into bmp pictures, which are relatively large. It is not recommended here to save unnecessary bytes, so the following software is recommended here.
Easygifanimator
Software download: animation splitter
The method of use is as follows:
Click on the file to export the frame file.
Once we have the frame file, we can write code, create a new anim animation folder in the res directory, and write the following code
The corresponding item is the sequence of pictures from start to finish, duration is the interval for playing each frame, oneshot is false for cyclic playback, and true is set to stop once playback.
The corresponding Activity code is written as follows:
Import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; public class animActivity extends Activity implements OnClickListener {ImageView iv = null; / * * Called when the activity is first created. * / @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.main); iv = (ImageView) findViewById (R.id.ImageView01); iv.setOnClickListener (this);} @ Override public void onClick (View v) {/ / TODO Auto-generated method stub AnimationDrawable anim = null; Object ob = iv.getBackground () Anim = (AnimationDrawable) ob; anim.stop (); anim.start ();}}
Use the AnimationDrawable object to get a picture of the picture, and then specify the AnimationDrawable to start playing the animation
Tip: using this method will not play the animation by default. You must have an event trigger to play the animation, such as the one above triggering the animation by clicking to listen.
So how to use the picture to play automatically? We can think of whether ProgressBar will turn by default, that is, the round progress bar, yes. We can modify it or play it automatically. Create a new styles file under the Values file and write the following code:
@ anim/test
The above style file is animated by Widget.ProgressBar.Large, and we can make it work for us by styling it in XML
OK, it's as simple as that. Let's see how it works:
This is the answer to the question about how to make the Gif animation move in the development of Android. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.