Resource IDs are automatically generated by Android for files inside the resource folder (/res
) only. Out of that folder, there is no such thing called "resource ID".
Some Android components (such as View
s) do have ID and can be set manually. However, manually-set ID is not listed inside R.java
, the collection of resource IDs generated by Android.
But in your case, generated images don't have ID, so it's impossible to get something that doesn't exist beforehand.
Regarding the library, there is another function to set the image from source without resource ID:
public void setMovie(Movie movie) {
this.mMovie = movie;
requestLayout();
}
Now, looking at the Movie
class which is included in Android SDK, there are other functions to decode a source: decodeByteArray()
and decodeFile()
. decodeByteArray()
accepts a byte array, and decodeFile()
accepts a file path, which can be used if you have the full path to the file.
While Bitmap
can be converted to byte array, I'm not sure whether Bitmap
supports multiple layers/animation of a GIF image, so I'll avoid the first approach. Instead, you can try this:
GifMovieView gifMovieView = ... ; // the reference to the view
String filePath = ... ; // the full file path to the GIF image
Movie myMovie = Movie.decodeFile(pathName);
gifMovieView.setMovie(myMovie);
(The above code is not tested yet)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…