飞溅屏幕图像使用主题的横向和纵向 [英] Splash Screen Image for landscape and Portrait using Theme
问题描述
我有两个全屏启动图像,一个用于横向,另一个用于肖像模式.我想将这些图像作为启动时根据设备启动时设备的方向来实现.
I have two full screens splash images, one is for landscape and another is for portrait mode.I want to implemented theses images as splash as per the orientation of the device when app starts.
例如,如果应用程序从横向模式启动,则应将横向图像显示为背景图像,如果应用程序从纵向模式启动,则应将纵向图像显示为背景图像. 我已引用以下示例
For Example if app starts from landscape mode than landscape image should be displayed as background image and if app starts from portrait mode than portrait image should be displayed as background image I have refer the following 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
I set this theme for splash activity from 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>
两个显示陆地和港口图像,我分别在drawable-land-hdpi
和drawable-port-hdpi
文件夹中放置了两个具有相同名称的图像splash_screen_1.jpg
图像
Two show land and port images i have place two images with same name splash_screen_1.jpg
images in drawable-land-hdpi
and drawable-port-hdpi
folders respectivley
活动:
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);
}
}
现在的问题是,当应用程序从纵向模式启动时,它可以完美运行,但是当我们从横向模式启动时,其带有纵向图像的启动应用程序会延伸几毫秒,然后它会将横向图像设置为小故障
Now the problem is when app starts from portrait mode its works perfectly but when we start from landscape mode its start app with portrait image stretch out for few milliseconds and than it sets the landscape images like a glitch
I tried Following solutions Link 1 Link 2
但是此解决方案不合适,因为它在开始时显示空白屏幕几秒钟以加载图像,并且从布局加载图像花费的时间很少
But this solution is not suitable because it shows blanks screen in the beginning for few seconds to load the images and its takes little more time to load images from layout
任何替代方法或适当的解决方案都会有所帮助
Any alternate or a proper solution for this will be helpful
推荐答案
这不是您的问题的答案,但是..
this is not answer of your Question But ..
Spash屏幕是等待活动准备就绪,而不是让用户等待更多时间
Spash screen is to wait till Activity Ready , Not to make user Wait more
那么尝试使用不同的方法来制作启动画面,它是内置的
so what about trying Diffrent way to make Splash screen , it`s built in
代替白屏或黑屏
转到清单
像这样更改您的应用样式
change your app style like this
<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为
where splashScreenTheme is
<style name="splashScreenTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
确定您可以更改父母 并制作新的可绘制"Splashscreen" 这是我的
Sure you can change parent and make new drawable "Splashscreen" this is mine
<?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中重置它
Now your app Style changed you can reset it in your main Activity Oncreate
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme222);
}
这篇关于飞溅屏幕图像使用主题的横向和纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!