facebook twitter hatena line email

Android/端末方向

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Resources resources = getResources();
        Configuration config = resources.getConfiguration();
        switch(config.orientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            Log.i("ORIENTATION", "PORTRAIT");
            break;
        case Configuration.ORIENTATION_LANDSCAPE:
            Log.i("ORIENTATION", "LANDSCAPE");
            break;
        }
    }
}

PORTRAITかLANDSCAPEの2択