java - 启动画面中的 GIF 不流畅
问题描述
我在我的启动画面(630kb,230 x 480)中实现了一个 Gif,它不是很流畅,在 MainActivity 启动前一秒钟它完全冻结了。
我正在使用 Glide 4.10
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
我的 SplashScreen.class
public class SplashScreen extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_splash);
ImageView imageView = (ImageView) findViewById(R.id.splashgif);
Glide.with(this)
.asGif()
.load(R.drawable.mygif)
.into(imageView);
Thread myThread = new Thread() {
@Override
public void run() {
try {
sleep(3000);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
myThread.start();
}
}
这是我的activity_splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/splash"
android:scaleType="centerCrop"/>
<ImageView
android:id="@+id/splashgif"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
我的应用程序包含许多小图像,这些需要一些时间才能加载,这可能是我的启动画面运行不流畅的原因吗?我能做些什么或者我必须接受它?
解决方案
最终 ImageView imageView = (ImageView) findViewById(R.id.splashgif);
runOnUiThread(new Runnable() {
@Override
public void run() {
Glide.with(getApplicationContext())
.asGif()
.load(R.drawable.mygif)
.into(imageView);
}
});
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}, 3000);
推荐阅读
- php - 为 wordpress 设置 maskedinput
- reactjs - React 如何渲染元素?
- jmeter - 如何使用 JMeter 使用连接到 VPN 而不是互联网的笔记本电脑系统进行性能测试
- python - 通过根据每一行选择第二个数据帧,有效地将一个数据帧与另一个数据帧合并
- r - 在 Raincloud Plot 中重新排序组
- javascript - React路由器在所有路由上使用精确呈现空白页面
- makefile - Makefile eval 函数导致文件意外结束
- eclipse - 当 Eclipse 显示打开文件列表在 Ubuntu 20.04 中的白色背景上显示白色文本时,我该如何解决
- webhooks - 没有身份验证的 Azure 事件中心侦听器
- snowflake-cloud-data-platform - 阶段的常见做法