【发布时间】:2020-04-12 16:52:52
【问题描述】:
我是安卓的初学者。我使用 android studio 创建了一个简单徽标的闪屏(1300x400 像素的 png),当我运行它时。我使用构建功能创建了一个 apk(在智能手机上尝试),但它没有加载图像(白屏 3 秒,然后应用程序启动)。是电话问题吗(一个简单的沃达丰 VFD 600)?
这是代码
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
activity_splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f1f1f1" >
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textSize="12dp"
android:textColor="#454545"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:text="www.codeseasy.com" />
</RelativeLayout>
SplashScreen.java
package com.example.splashscreen;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends AppCompatActivity {
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
@override public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class); startActivity(i);
finish(); } }, 5000);
}}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.splashscreen">
<application
android:allowBackup="true"
android:icon="@Mipmap/ic_launcher"
android:label="@String/app_name"
android:roundIcon="@Mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@Style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".SplashScreen"
android:theme="@Style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.kt
package com.example.splashscreen
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
早上好,我在另一部智能手机华为 p10 上尝试了该 apk,它可以工作。此时问题一定出在智能手机上。另一个问题:是否可以放视频而不是图像?显然在视频中不能出现前进、后退、停止键……谢谢。
【问题讨论】:
-
徽标是否在正确的文件夹中?当您在 Android Studio 文件资源管理器上看到徽标文件时,您是否看到类似“drawable-xhdpi”的内容?或者类似的东西?
-
为什么要加载图片?放到drawable文件夹中使用
-
您的应用在模拟器中可以正常运行吗?
-
MohammadMoeinGolchin 是的
-
库蒂科。 png 文件位于 res / drawable 文件夹中,名称为 logo.png
标签: android android-layout splash-screen