I have a LottieAnimationView in my xml file. I want to add custom image that comes dynamically from backend(avatar image) in that lottie animation view, I mean in lottie animation view add image in its background. This is my LottieAnimationView:
<com.airbnb.lottie.LottieAnimationView
android:id="#+id/lottie_animation"
android:layout_width="110dp"
android:layout_height="110dp"
app:lottie_autoPlay="true"
app:srcCompat="#drawable/custom"
app:lottie_rawRes="#raw/photo_animation"
app:lottie_loop="true"
app:lottie_speed="2.5" />
But its only showing my animation, not showing imageview at all.
Could you post any ideas how can I handle it?
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
I am trying to center the same logo for the launch screen and login screen, one a bitmap and one an ImageView respectively, the images are slightly off from one another
Here is the bitmap XML snippet:
<bitmap
android:src="#drawable/logo"
android:gravity="center"/>
Here is the ImageView XML snippet:
<ImageView
android:id="#+id/logo_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerInside"
android:visibility="gone"
android:src="#drawable/logo"/>
I have tried to change the ImageView's scaleType variable (tried "fitXY" and "fitCenter") but no luck.
To reiterate, my goal is to have the ImageView's logo be at the exact same spot as the bitmap's logo, when the launch screen disappears.
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);
I have a ImageView with the following layout
<ImageView
android:id="#+id/view_row_circular_icon_with_text_icon"
style="#style/ImageView"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_gravity="right|center_vertical"
android:padding="5dp"
android:src="#drawable/ic_broadband_router_white"/>
The android:src property is useful for previewing this component.
And I set the image I want do display with the following
ImageView mIcon = (ImageView) findViewById(R.id.view_row_circular_icon_with_text_icon_bg);
mIcon.setImageDrawable(rowEntry.getIcon());
rowEntry.getIcon() returns a Drawable.
The end result is both the image from android:src property and the image set from mIcon.setImageDrawable() in the ImageView.
How can I programmatically override the image so that only the latter is shown?
As i can see that your setting image of a another view which
R.id.view_row_circular_icon_with_text_icon_bg
Check the proper id and set the image
I have an ImageView
<ImageView
android:id="#+id/auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:src="#drawable/auto" />
How can I add layout for this image in onCreate for Activity? For instance, I want add background for this image. Thanks.
Enclose it in a Layout and add a background to the Layout.