2011-09-11 77 views
4

當屏幕小於(例如)480px時,任何人都知道如何禁用我的Android應用中的屏幕旋轉? 我正在構建應用程序,使用phonegap女巫將針對平板設備,但它也可以在智能手機上運行它。不幸的是應用程序時以橫向顯示的應用程序只顯示正常......Android:屏幕小於x時禁用屏幕旋轉

+0

我做到了,但我必須等待8個小時(6個以上)來回答我的問題(我有<100代表...) – PsychoX

回答

4

也許一個「如果」控制

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

onCreate函數?

4

幹了! :)

這裏是如何(言自明):

int width; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    super.loadUrl("file:///android_asset/www/index.html"); 
    Display display = getWindowManager().getDefaultDisplay(); 
    width = display.getWidth(); 
    if(width <= 480) { 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    } 

} 


@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    if(width <= 480) { 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    } 
}' 

和幾個進口:

import android.content.pm.ActivityInfo; 
import android.content.res.Configuration; 
import android.view.Display;' 
0

結合@Howard霍德森和在此線程How to determine device screen size category (small, normal, large, xlarge) using code?

我使用該解決方案此代碼:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    disableLandscapeInSmallDevices(); 
} 

private void disableLandscapeInSmallDevices() { 
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    } 
}