2012-09-23 87 views
1

我製作了一款在模擬器以及中小尺寸手機中工作正常的應用程序。但在平板電腦上運行時,它始終只顯示風景模式。我還使用了單獨的佈局和佈局土地layouts.I我沒有得到背後就是原因是代碼:應用程序始終在平板電腦上顯示風景模式

public class SplashActivity extends FragmentActivity 
{ 
    public void onCreate(Bundle paramBundle) 
    { 
    super.onCreate(paramBundle); 
    requestWindowFeature(1); 
    getWindow().setFlags(1024, 1024); 

    FragmentManager fragmentmanager = getSupportFragmentManager(); 
    FragmentTransaction fragmenttransaction = fragmentmanager.beginTransaction(); 
    if (getResources().getConfiguration().orientation == 
     Configuration.ORIENTATION_LANDSCAPE) { 
     setRequestedOrientation(0); 
    } 
    else 
    { 
     setRequestedOrientation(1); 
    } 
    fragmenttransaction.commit(); 

    setContentView(R.layout.welcome); 
    new Handler().postDelayed(new SplashThread(), 2000L); 
    } 

    class SplashThread implements Runnable 
    { 
    SplashThread() 
    { 
    } 

    public void run() 
    { 
     SplashActivity.this.startActivity(new Intent(SplashActivity.this, McqHomePage.class)); 
     SplashActivity.this.finish(); 
    } 
    } 
} 

請幫助me.Thanks提前。

+0

請幫幫我。 – user1662334

回答

1

如果你不關心的方向,你還不如離開了這段代碼完全:

if (getResources().getConfiguration().orientation == 
     Configuration.ORIENTATION_LANDSCAPE) { 
     setRequestedOrientation(0); 
    } 
    else 
    { 
     setRequestedOrientation(1); 
    } 

上面還有代碼有醜陋的副作用,即某些方向的變化總是導致在縱向 - 例如,反向橫向不會被您的代碼捕獲。此外,請不要使用0或1,而應使用提供的常量,以便如果值更改,您的代碼不會中斷。

在此期間,請檢查您的manifest - 我敢打賭,您在那裏添加了方向屬性。

+0

先生,其實我已新增下列在我的清單文件代碼:<支持屏 機器人:anyDensity =「真」 機器人:largeScreens =「真」 機器人:normalScreens =「真」 機器人:調整大小=「真」 android:smallScreens =「true」/> – user1662334

+0

爲什麼佈局和佈局土地概念不適用於平板電腦的情況呢? – user1662334

+0

謝謝你的幫助先生。 – user1662334

相關問題