I have a coloured gif image that I would like to use in my application, I imported the image into my application by dropping and dragging the gif into res/drawable.
However the transparent background turns white when it is shown in an imageview, here is my code
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="#drawable/logo"/>
How can I make android show the transparent background and not a white one?
Thanks
I think its better to open a gif in a webview. you can put the gif file in a html file and open it in webview. also you can set your app background in html file to make your work easier.
Related
How can I remove white background around image when loading with glide.. You can find out below code as well as screenshot;
Glide.with(thiscontext).load(R.drawable.badge_green_yellow)
.asGif().crossFade()
.diskCacheStrategy(DiskCacheStrategy.SOURCE).into(holder.ivHourlyIcon);
ScreenShot
Put your GIF into the raw folder (res/raw/badge_green_yellow.gif)
and then load it like this
Glide.with(thiscontext).asGif().load(R.raw.badge_green_yellow).into(holder.ivHourlyIcon);
In my android application I downloaded some png image and write them in sd card. when I show them in image view they are showing with black background. the original images have transparent background. How I can keep the background transparent. Please help me. I use PNG format to compress and write it to sd card
Set The View Background as
R.color.transparent
or in xml like
android:background="#android:color/transparent"
Edited :
Thanks for reply. yes I did this. I did just now One more thing, I set canvas color android.R.color.transparent and it worked
I have a problem.
I have fragment with ViewFlipper and some string data array (images urls).
How do I do a lazy load of these images and show progressbar until the image is loaded(And caching them if possible)?
Can I use a different view(not ViewFlipper)?
And second question. How do I make a View showing the current image position? Such as a series of white dots with a black under the current picture. If the current image of the first - the first black dot.
Thanks.
Google has a training class answering your first question here. It shows you how to load a bitmap in the background using an AsyncTask and caching it both in memory with an LruCache and on the disk with a DiskLruCache (included in the BitmapFun.zip download found at the link) while displaying a ProgressBar until the image is downloaded
Can I use a different view(not ViewFlipper)?
The aforementioned example uses a ViewPager.
a series of white dots with a black under the current picture.
I do not know if there is such a view available from the Android SDK but this third party widget (Apache 2.0 license) seems to do what you want.
How i can keep link on ImageView and ProgressBar?
I am not sure I understand the question but if you are asking how you go from the ProgressBar (while the image is loading) to the ImageView then the answer is to use a FrameLayout with the ProgressBar and ImageView in it:
<FrameLayout ...>
<ProgressBar ... />
<ImageView
android:id="#+id/imageView"
... />
</FrameLayout>
(see image_detail_fragment.xml in the exercise for more details)
The ImageView will be drawn in front of the ProgressBar but as it will originally have no background and no image it will be transparent and the ProgressBar will be showing.
You then retrieve the ImageView from your code using its id and when you have loaded your image in a Bitmap you use:
imageView.setImageDrawable(loadedImage);
Now that the ImageView has an image it will not be transparent anymore and the ProgressBar will not be showing (you can also add an id to the progress bar if you want to set it to View.GONE to optimise your layout).
i want to play gif use web view,default webview background is white.so i use :
webView.setBackgroundColor(Color.TRANSPARENT);
but when i use the above code,my gif can play,but behind of my gif it also draw one pic of gif
as:
In the pic you will see a redundant pic at the behind. My original gif pic is like this:
When I was trying to delete webView.setBackgroundColor(Color.TRANSPARENT), the gif was showing good, but background was white.
When i add the code, my gif always have a a redundant pic of the gif.
So my question is: how can I set my gif background as transparent but not mess up the gif?
I use an ImageView control as shown:
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/imgHangMan"
android:src="#drawable/hang0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
The above code displays the image in the Graphical Layout preview of the xml file. But on launching the app, I see no image. Also, changing the image using
imgHangMan = (ImageView)findViewById(R.id.imgHangMan);
imgHangMan.setImageResource(R.drawable.hang1);
This piece of code also does not work either. The image files are in .gif format and are in the drawable folder.
Any pointers ?
Natively ImageView doesnot support animated image. You have two options to show animated gif file
1) Use VideoView 2) Use ImageView. But Split the gif file into several parts and then apply animation to it.
Try this link-playing-gif-animation you will get the desired result.
Try this
image.setImageDrawable(getResources().getDrawable(R.drawable.hang1));
User this :
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Go by this.