我是 android 编程的新手。我试图制作一个闪屏,我有两个不同的图像......一个用于背景,另一个用于 Logo ......两个图像都在单独的 ImageView 中。图像的大小分别约为 23kb 和 3kb。但是当我运行应用程序时。它显示处理器可能正在执行额外工作的错误。跳过 88 帧。这将完全跳过启动画面并直接进入主要 Activity 。请任何人帮助我解决这个问题。
最佳答案
在父级中设置背景图像,并在子级中提供 Logo 图像... 像这样:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgroundImage"
tools:context="xyz.xyz.com.xyz.activity.SplashActivity">
<ImageView
android:id="@+id/logoImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="@drawable/logoImage" />
</RelativeLayout>
在 java 代码中使用这个:-
public class SplashActivity extends AppCompatActivity {
private long ms = 0;
private long splashTime = 2000;
private boolean splashActive = true;
private boolean paused = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread mythread = new Thread() {
public void run() {
try {
while (splashActive && ms < splashTime) {
if (!paused)
ms = ms + 100;
sleep(100);
}
} catch (Exception e) {
}
finally
{
System.out.println("reached");
Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
System.out.println("reached1");
startActivity(intent);
System.out.println("reached2");
finish();
System.out.println("reached3");
}
}
};
mythread.start();
}
关于java - 安卓闪屏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48608685/