James Fazio
James Fazio

Reputation: 6450

Android Capture Orientation Change

I have two background images. I want Image A to display when the screen is horizontal and Image B to display when the screen is vertical. Any easy way of achieving this?

Upvotes: 1

Views: 327

Answers (4)

Padma Kumar
Padma Kumar

Reputation: 20041

Do this

Result Values for Oreintations will be:-  
Portrait  == 1  
Landscape == 2    
int i = context.getResources().getConfiguration().orientation;
if (i == Configuration.ORIENTATION_PORTRAIT) {
   yourimg.setBackground(yourAimage);
} else {
   yourImg.setBackground(yourBimage);
}

Upvotes: 2

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21191

take two images A & B. save image A in drawable-land and image B in drawable-port

note that the images are saved with same names..

you can check this in graphic layout also..

Upvotes: 1

SilentKiller
SilentKiller

Reputation: 6942

Create each XML for horizontal & Vertical

Create one more folder name "layout-land" n just coy & paste the main.xml(your layout file) and just change the background respectavely.

you'll done...

Upvotes: 0

android
android

Reputation: 666

you can create two xml layouts here one for landscape and other for portrait. In portrait xml you can add different images for background. By this we can use two different layouts for two orientations for a single activity. see the below picture, hope it should help.

image

Upvotes: 1

Related Questions