【问题标题】:Splashscreen in Android app: image is not loadingAndroid 应用程序中的启动画面:图像未加载
【发布时间】: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


【解决方案1】:

您能否检查一下您的 png 是否很大。因为 imageView 通常不喜欢大图像。 如果您仍然想继续,请尝试更改图像分辨率,然后它就可以正常工作。 从这篇文章中检查 re-size 方法。Activity runs slow with a couple of ImageView-s

希望对你有帮助

【讨论】:

  • 感谢回复...我在另一部智能手机华为p10上尝试了apk,它可以工作。此时问题肯定出在智能手机上。
  • 你是对的。这可能是特定于设备的问题,但在构建应用程序时,你仍然不能忽略任何特定的设备。
猜你喜欢
  • 2011-10-25
  • 2012-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-19
相关资源
最近更新 更多