我在启动画面中实现了一个 Gif (630kb, 230 x 480) 它不是很顺利,在 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);
关于java - 启动画面中的 GIF 不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58836417/