【问题标题】:splash screen is not showing on whole screen on mobile启动画面未显示在移动设备的整个屏幕上
【发布时间】:2016-06-27 09:26:07
【问题描述】:

我正在开发 android 项目,我正在处理启动屏幕代码,但启动图像没有显示在我的手机的整个屏幕上我的活动代码是:-

public class SplashPresenter extends MvpBasePresenter<SplashView> {

    @Override public void attachView(SplashView view) {
        super.attachView(view);
        new Handler().postDelayed(new Runnable() {
            @Override public void run() {
                launch();
            }
        }, 2000);
    }

    @Override public void detachView(boolean retainInstance) {
        super.detachView(retainInstance);
    }

    private void launch() {
        String imei = ImeiUtil.getIMEI();

        List<ActivationInfo> infos = ActivationInfo.listAll(ActivationInfo.class);
        if (infos.size() == 1) {
            ActivationInfo info = infos.get(0);
/*
            Log.d("I: ", "I: " + info.getBusinessName());
            Log.d("I: ", "I: " + info.getMobileNumber());
            Log.d("I: ", "I: " + info.getImei());
            Log.d("I: ", "I: " + imei);
            Log.d("I: ", "S: " + info.getStatus());
*/
            if (info.getStatus() == 1 && info.getImei().equalsIgnoreCase(imei)) {
                getView().start(HomeActivity.class);
            } else {
               //getView().start(ActivationActivity.class);
            getView().start(HomeActivity.class);
            }
        } else {
           getView().start(HomeActivity.class);
        //  getView().start(RegisterActivity.class);
        }
    }

xml 代码是,我在这里展示过

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:contentDescription="@string/splash_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:src="@drawable/splash_english"/>

</RelativeLayout>

【问题讨论】:

  • 显示你的 res/style.xml 和清单文件
  • 可以提供截图吗?

标签: android xml splash-screen


【解决方案1】:

以正确的方式实现启动画面与您想象的有些不同。您看到的启动视图必须立即准备好,甚至在您可以在启动活动中扩展布局文件之前。您不会使用布局文件。相反,将启动屏幕的背景指定为活动的主题背景。为此,首先在 res/drawable 中创建一个 XML drawable。它是 xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/gray"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

接下来,您将在主题中将此设置为启动活动的背景。导航到您的 styles.xml 文件并为您的启动活动添加一个新主题:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
    </style>

</resources>

您的 SplashActivity 类应该只是将您转发到您的主要活动:

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

完整的源代码可以在这里下载https://github.com/shubhamsharmacs/Splash

【讨论】:

    【解决方案2】:
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    
    <ImageView
        android:contentDescription="@string/splash_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:src="@drawable/splash_english"
        android:minHeight="1000dp"
        android:minWidth="1000dp"/>
    
    </RelativeLayout>
    

    【讨论】:

      【解决方案3】:

      如果您只是想让图像填满屏幕,请将您的 android:scaleType 更改为 fitXY 之类的内容。依靠 minHeight 和 minWidth 并使用 centerCrop 并不能很好地覆盖多种设备尺寸。更好的解决方案,开发尺寸更好的图像或使用基于 xml 的 drawables

      【讨论】:

        【解决方案4】:

        在 Activity 的 onCreate 方法中添加这一行

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-07-23
          • 1970-01-01
          • 2015-01-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多