java - Android 应用启动时不显示 GIF
问题描述
我在尝试在我的应用程序中使用 GIF 时遇到问题。当我运行我的应用程序时,它根本不会出现。我遵循了有关如何使其工作的教程,所以我不知道为什么它不工作。我也没有收到任何错误消息。所以,我的问题是,有人对为什么会发生这种情况有任何建议吗?提前感谢您的帮助!
我的代码:
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" />
解决方案
尝试这个:
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();
}
推荐阅读
- python - 自动化我创建 virtualenv 和 django 的任务
- java - 为什么子类对象引用父类值
- laravel - 当我使用 laravel 重新加载页面时,我想显示第一类产品?
- r - 有没有办法在 R 中将变量存储为数字但显示为 date9 格式?
- c# - 如何抑制用户对 ListBox 控件的操作
- angular - 如何在ag-grid中将特定列的部分标题名称更改为小写
- python - pd.ExcelWriter,追加日期时间但得到:未知或不支持的日期时间类型
- node.js - 尝试在arrayOfObject中使用分页(每页10条记录)
- karate - 如何在空手道 UI 自动化中使用 if-else
- reactjs - Material Ui TextField 移除底部边框