【问题标题】:Splash Screen Image for landscape and Portrait using Theme使用主题的横向和纵向启动画面图像
【发布时间】:2017-08-19 22:46:20
【问题描述】:

我有两个全屏启动图像,一个用于横向,另一个用于纵向模式。我想在应用启动时根据设备的方向将这些图像实现为启动。

例如,如果应用程序从横向模式启动,则应将横向图像显示为背景图像,如果应用程序从纵向模式启动,则应将纵向图像显示为背景图像 我参考了以下Example

这就是我设置主题的方式:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen_1</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

我为 AndroidManifest.xml

中的启动活动设置了这个主题
    <activity
            android:name=".activities.SplashActivity"
            android:allowBackup="true"
            android:label="@string/app_name"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

两个显示陆地和港口图像我将两个具有相同名称的图像splash_screen_1.jpg 图像分别放在drawable-land-hdpidrawable-port-hdpi 文件夹中

活动:

public class SplashActivity extends AppCompactActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        startApp();
    }

    private void startApp() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                    HomeActivity.startHomeActivity(SplashActivity.this);
                finish();
            }
        }, 2000);
    }
}

现在的问题是,当应用程序从纵向模式启动时,它可以完美运行,但是当我们从横向模式启动时,它的纵向图像启动应用程序会拉伸几毫秒,然后它将横向图像设置为故障

我尝试了以下解决方案 Link 1 Link 2

但此解决方案不适合,因为它会在开始时显示空白屏幕几秒钟以加载图像,并且从布局加载图像需要更多时间

任何替代或适当的解决方案都会有所帮助

【问题讨论】:

  • 根据您的问题中的链接 1 的解决方案应该可以工作。您是否创建了单独的文件夹并在其中添加了布局文件?图像与纵向图像不同?
  • 是的...但正如我上面提到的从布局加载图像需要很多时间导致显示空白屏幕几秒钟
  • 那么也许你应该优化图像。它不应该发生。
  • 图像已经过优化,当我们将它们设置为主题背景时,它的工作正常......但它有一个我已经提到过的故障问题
  • 为什么要投反对票??

标签: android android-layout splash-screen android-theme


【解决方案1】:

这不是你问题的答案,但是..

闪屏是等到Activity Ready,而不是让用户等待更多

那么尝试不同的方式来制作启动画面呢,它是内置的

而不是白屏或黑屏

去你的清单

像这样改变你的应用风格

<activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/splashScreenTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

splashScreenTheme 在哪里

<style name="splashScreenTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
    </style>

当然你可以改变父母 并制作新的可绘制“闪屏” 这是我的

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
    <!-- The background color, preferably the same as your normal theme -->
    <item android:drawable="@android:color/holo_blue_light"/>
    <!-- Your product logo - 144dp color version of your app icon -->
    <item>
        <bitmap
            android:src="@drawable/splash_logo"
            android:gravity="center"/>
    </item>
</layer-list>

现在您的应用样式已更改 您可以在主 Activity Oncreate 中重置它

@Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme222);
}

【讨论】:

  • 但我想根据方向加载横向和纵向飞溅
【解决方案2】:

如果您必须使用主题方法,请创建一个单独的 styles.xml 文件到新的 values-land/ 文件夹到 res 文件夹中。 ..

【讨论】:

  • 故障仍然存在同样的问题。首先它加载拉伸纵向图像,然后几秒钟后加载横向图像
  • @BurhanuddinRashid 你找到解决这个问题的方法了吗?我也面临这个问题。
猜你喜欢
  • 1970-01-01
  • 2019-10-19
  • 1970-01-01
  • 2014-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多