Reputation: 264
I'm having trouble with a GIF that I'm trying to use in my app. When I run my app it simply just doesn't appear. I followed tutorials on how to make it work so I have no idea why it doesn't. I also don't get any error messages either. So, my question is does anyone have any suggestions on why this is happening? Thanks in advance for any help!
My code:
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
}
}
allprojects
{
repositories
{
mavenCentral()
google()
jcenter()
}
}
App build script:
dependencies {
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
}
XML:
<pl.droidsonroids.gif.GifImageView
android:layout_width="match_parent"
android:layout_height="60dp"
app:srcCompat="@drawable/gif" />
Upvotes: 1
Views: 349
Reputation: 197
TRY THIS:
XML:
<pl.droidsonroids.gif.GifImageView
android:id="@+id/gif_view_offer"
android:layout_gravity="center"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:src="@drawable/checkmark"
android:layout_marginBottom="10dp"/>
JAVA:
GifImageView gifView;
GifDrawable gifFromResource = null;
gifView = (GifImageView) v.findViewById(R.id.gif_view_offer);
try {
gifFromResource = new GifDrawable(activity.getResources(), R.drawable.lockgif);
gifView.setImageDrawable(gifFromResource);
} catch (IOException e) {
gifView.setVisibility(View.GONE);
e.printStackTrace();
}
Upvotes: 1
Reputation: 1943
I strongly recommend you to implement Lottie
instead. It supports a different kind of formats and autoPlay feature also.
https://github.com/airbnb/lottie-android
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lavSplash"
app:lottie_rawRes="@raw/splash"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="@style/Widget.Custom.Lottie"/>
<style name="LottieAppearance">
<item name="lottie_loop">true</item>
<item name="lottie_autoPlay">true</item>
<item name="android:layout_width">@dimen/wrap_content</item>
<item name="android:layout_height">@dimen/wrap_content</item>
</style>
<style name="Widget.Custom.Lottie" parent="LottieAppearance" />
Upvotes: 1