アプリに向きを追加したいのですが、それが必要です-> PORTRAITスタイルの電話がAアクティビティとして機能し、PORTRAITスタイルをLANDSCAPEスタイルAアクティビティが停止してBアクティビティが開始するように変更した場合これを処理するにはどうすればよいですか?ありがとう...
4 に答える
2
これを行う
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
//here call activity A
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
//here call activity B
}
}
于 2012-08-06T12:28:28.673 に答える
1
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
}
if (getResources().getConfiguration().orientation ==Configuration.ORIENTATION_LANDSCAPE)
{
}
于 2012-08-06T12:27:31.133 に答える
1
Activity B
以下のコードから始めてください-
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Intent a = new Intent(this, B.class);
startActivity(a);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
//do nothing
}
}
そして、あなたのAndroidManifest.xml
ファイルの両方の活動タグで。以下のように宣言してください
<activity android:name=".A"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
于 2012-08-06T12:30:15.127 に答える
0
まず、次のように向きを確認します。
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getOrientation();
オリエンテーションの価値に応じて、必要なアクティビティを開始します。
次に、アクティビティでこのメソッドをオーバーライドします。
public void onConfigurationChanged(Configuration newConfig) {
//start the other activity
}
于 2012-08-06T12:28:16.820 に答える