Robin Walter‎ > ‎Blog‎ > ‎

Android: Ermitteln der Bildschirmauflösung

veröffentlicht um 23.01.2011 08:59 von Robin Walter   [ 24.01.2011 11:59 wurde aktualisiert. ]
um evtl. Grafiken skalieren zu können, Views auszuwählen oder was auch immer, kann es schon mal vorkommen, dass ihr vom Gerät wissen wollt wie breit und hoch das Display ist.

Code

Display display = getWindowManager().getDefaultDisplay();
int screenHeight = display.getHeight();
int screenWidth = display.getWidth();



und wenn wir schon dabei sind: Querformat oder Hochformat?

Code

int orientation = getResources().getConfiguration().orientation;

if (orientation == Configuration.ORIENTATION_PORTRAIT) {
         // do something
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
         // do something else
}


Adresse

Robin Walter
Walter-Förster-Str. 3
76316 Malsch
Tel: +49 7246 449314
Mobil: +49 1578 2432487
E-Mail: mail@robin-walter.de

Paketadresse:
Robin Walter
3181110
PACKSTATION 801
76187 Karlsruhe

That´s me: