2016-03-13 24 views
0

我正在開發一個Android應用程序,我需要設置單獨的啓動屏幕,一個用於縱向,一個用於橫向。兩者都是不同的圖像。我該怎麼做?如何在Android中爲橫向和縱向模式設置單獨的啓動畫面?

activity_splash.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" 
    > 

    <ImageView 
     android:id="@+id/imgLogo" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/wwe_logo" /> 

</RelativeLayout> 

SplashScreen.java

public class SplashScreen extends Activity { 

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

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

     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(SplashScreen.this, MainActivity.class); 
       startActivity(i); 

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

} 
+1

的[XML佈局的變化,而可能的複製改變方向](http://stackoverflow.com/questions/9630952/xml-layout-changes-while-changing-orientation) – Yazan

+0

It's Working ..謝謝你soo .. Answare標記:D –

回答

0

化妝2個不同的佈局,相同的文件名,並把佈局,土地的景觀佈局,並在默認佈局 則無需處理來自Java類的任何畫像

0

如果兩個佈局是賺不到layoutlayout-land那麼您可以在onCreate做手工用setContentView之前後自動切換

if (this.getWindow().getWindowManager().getDefaultDisplay() 
        .getOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { 
       setContentView(R.layout.activity_splash_portrait) 
      } else { 
       setContentView(R.layout.activity_splash_land) 
      } 
+2

有一個正確的方法在'/ res /'中處理這個使用XML佈局文件和文件夾命名。 – Yazan

+1

感謝兄弟,我認爲他知道爲橫向和縱向創建不同的XML,並且他沒有自動獲取佈局。所以我添加了替代解決方案。 –

相關問題