Android splash screen for both landscape and portrait orientation

自作多情 提交于 2019-12-06 09:45:16

问题


How can I modify my this code to set splash screens for both landscape and portrait orientation. I managed to work on portrait mode and it is working fine. i like ti make it for both the orientation. please modify this code. This is my SplashActivity.java.

public class SplashActivity extends Activity {


  // Splash screen timer
 private static int SPLASH_TIME_OUT = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_screen);



    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashActivity.this, MainActivity.class);
            startActivity(i);

            // close this activity
             finish();
          }
       }, SPLASH_TIME_OUT);
    }

  }

This is my 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="wrap_content" >


  <ImageView
     android:id="@+id/imgLogo"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:adjustViewBounds="true"
     android:scaleType="centerCrop"

     android:src="@drawable/screen_portrait"

     />
</RelativeLayout>

回答1:


For having splash screen for landscape screen. follow below steps.

  1. Create folder layout-land under res folder.
  2. In that folder, copy splash_screen.xml file.
  3. Change src resource portrait splash image to your landscape splash image

Appropriate file will be loaded at run-time automatically. no need to change in java code




回答2:


i think problem with you manifest file. and please describe your main problem.

<activity
        android:name=".SplashActivity"
        android:configChanges="keyboard|orientation|screenSize"
        android:label="@string/app_name"
        android:theme="@style/AppLoginTheme"
        android:windowSoftInputMode="adjustResize" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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


来源:https://stackoverflow.com/questions/28736641/android-splash-screen-for-both-landscape-and-portrait-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!