I have an issue with the GIF Resizing.
My GIF dimensions is 136*136 px and I'm trying to load it into an image view (that has its width and height set as wrap_content) using Glide library. But the GIF ends up taking the entire screen.
My XML file code snippet looks like below:
ImageView
android:id="#+id/loading_animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
tools:src="#drawable/gif_loading_animation"
android:foregroundGravity="center" />
And My main activity code looks something like this:
Glide.with(getContext())
.load(R.drawable.gif_loading_animation)
.asGif()
.into(loadingAnimation);
Is there any solution to avoid resizing without using any hard code parameters width and height.
:)
You can try using .override(Target.SIZE_ORIGINAL)
Glide.with(getContext())
.load(R.drawable.gif_loading_animation)
.asGif()
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(loadingAnimation);
Related
I am in the process of writing an app and wanted to have a Lottie animation as my splash screen, since I am learning java as I code this app I made a test app to see how things would work. I found that almost any Lottie animation displays just as a still image and does not play/loop the animation. I followed the guide on LottieFiles website and also information that I found on other questions but I still did not manage to get the animation playing. The following is exactly what I have added:
Gradle dependency of my app:
dependencies {
implementation 'com.airbnb.android:lottie:3.6.1'
}
To my Layout XML:
<com.airbnb.lottie.LottieAnimationView
android:id="#+id/splashlottie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_fileName="opening_book.json" //Even tried placing the file in raw and using app:lottie_rawRes="#raw/opening_book"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
In my activity:
LottieAnimationView splashscreen;
splashscreen = findViewById(R.id.splashlottie);
splashscreen.animate();
splashscreen.playAnimation();
I am not sure exactly what I am doing wrong as I even tried various different lottie animation files and by placing the same file under raw and assets. Could the API level be the cause of the animation not playing?
Looks like you are doing it right. Is there any chance of animations are completely disabled on your phone?
I was able to run the animation with the following code:
val imageView = view.findViewById<LottieAnimationView>(R.id.image_view)
imagView.playAnimation()
xml code:
<com.airbnb.lottie.LottieAnimationView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_fileName="womensDay.json"
app:layout_constraintBottom_toTopOf="#+id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview_first"
app:lottie_loop="true"/>
A few things to remember:
Make sure you're placing your json file in the asset folder, if don't have one create one. Refer: https://stackoverflow.com/a/50907775/5745574
Just to test, try giving your view absolute dimension say 200dp (width & height). It might be a case where your view doesn't have proper dimension.
Try animating a different json file, your file may be corrupted
Try placing your lottieView inside a ViewGroup (Of any type e.g. LinearLayout)
Lottie animation is supported in API level 16 and above
This is work without lottieView.playAnimation() because lottie_autoPlay="true":
<com.airbnb.lottie.LottieAnimationView
android:id="#+id/anim_view"
android:layout_width="256dp"
android:layout_height="256dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_rawRes="#raw/anim_radio_waves"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>
Also check your animation json: lottie player
How can I zoom ImageView like Instagram. I mean changing the size of imageview, not zooming the image inside the Imageview.
For zooming the image inside the Imageview, there are a lot of samples but I want something like Instagram image zooming
Any code or hint? Thanks.
I recommend Zoomy, very simple and functional.
Just add the following to your current ImageView:
Zoomy.Builder builder = new Zoomy.Builder(this).target(mZoomableView);
builder.register();
I would recommend these two libraries:
PhotoView
ImageViewZoom
For PhotoView, you just have to create an attacher and "attach" it to your ImageView.
Some code
// After getting your imageImage view, attach it like the following
PhotoViewAttacher yourAttacher = new PhotoViewAttacher(yourImageView);
With just this code, you'll be able to zoom in/out/whatever on yourImageView. Check the links above for more details.
EDIT
Instagram has changed a lot since this answer was posted, and the libraries I recommended above might not provide the experience you are looking for.
thanks
I have added this to my gradle.build
compile 'it.sephiroth.android.library.imagezoom:imagezoom:2.2.5'
and then using this view
<it.sephiroth.android.library.imagezoom.ImageViewTouch
android:id="#+id/mp3Image"
android:adjustViewBounds="true"
android:layout_width="346dp"
android:layout_height="356dp"
android:scaleType="fitCenter" />
and the below code, the zoom came to my app
myImage = (ImageViewTouch) findViewById(R.id.mp3Image);
myImage.setDisplayType(ImageViewTouchBase.DisplayType.FIT_IF_BIGGER);
Why I can't display images in a large size, its results even smaller, is there something wrong with my XML code? or errors are in the java code? And i have "[Accessibility] Missing contentDescription attribute on image" on my XML code in ImageView
This my code :
Detail.xml
<ImageView
android:id="#+id/ivPosterImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:maxHeight="300dp"
android:src="#drawable/large_movie_poster" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ivPosterImage"
android:layout_marginTop="10dp" android:id="#+id/scrollView1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Activity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_box_office_detail);
// Fetch views
ivPosterImage = (ImageView) findViewById(R.id.ivPosterImage);
....
Picasso.with(this).load(movie.getLargePosterUrl()).
placeholder(R.drawable.large_movie_poster).
into(ivPosterImage);
Please help me ...
Its clearly looking that your downloaded image have very small height and width dimension and you have settled the dimension around wrap_content. That's why you are getting this small icon instead of full image.
And again image download libs always use image attribute setSource in their code, which also set image around wrap_content.
Now you have 2 choice to show image wider:
set width = match parent,
height = fixed(any value as per your choice like 100 dp ,200 etc), i have not fixed the width because thats goona create exception on small or large screns.
set image background instead of image src that is by default set by image download libs.
Hopefully this will resolve your issue.
In android, if you create an imageview in the xml code like this:
<ImageView
android:id="#+id/picture_avatar"
android:layout_width="90dp"
android:layout_height="110dp"
android:background="#bdbdbd" />
How can you tell in the java code, if it has a set image?
There is another button that sets an image using the setImageBitmap function. So I want to tell if it has an image or not.
Thanks
pictureavatar.getDrawable() == null
If true, then no image else it has an image
So I'm loading images from a web service, but the size of the images are sometimes smaller or bigger than other images and the visualization looks silly when I put them in a ListView in android. I'd like to fix the size of my ImageView so that it only shows a portion of the image if it's larger than a preset amount. I've tried everything I can think of setting the setMaxWidth/setMaxHeight, setting the scale type to centerCrop, using ClipableDrawable wrapping my BitmapDrawable, setting using Drawable.setBounds(). I've tried setting in the XML and programmatically, but neither worked. I'm very surprised setting max width/height didn't do anything. Below is the XML I'm using ImageView definition in my layout file:
<ImageView android:id="#+id/recipeImage"
android:maxHeight="64px"
android:maxWidth="64px"
android:scaleType="centerCrop"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"/>
But,nothing has worked.
Just delete the maxHeight and maxWidth attributes and enter your units in layout_width and layout_height appropriately. But do not use the px unit - use dp instead, because these are device-independent.
This will fit the image in the specified height and width, irrespective of image size.
<ImageView
android:id="#+id/image5"
android:layout_width="300dp"
android:layout_height="200dp"
android:src="#drawable/image_1"
android:scaleType="fitXY"/>
Get ImageVIews as facebook posts.
Glide.with(context).load(link)
.placeholder(R.drawable.aboutlogo)
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);`
<ImageView
android:id="#+id/img1"
android:src="#drawable/ic_menu_camera"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"/>