How to change background when changing screen orientation on Android

-2

I'm developing an Android application where the background image only gets cool when the phone sits upright. I would like every time the user changes the screen orientation the background changes to an image that looks nice without being stretched out.

    
asked by anonymous 31.12.2015 / 17:51

2 answers

1

You could use a vectored image, but if you do not want to do this, just do the following:

1st = > change the view of your project from "android" to "project".

2nd=>Thencreatethedrawable-landanddrawable-portfoldersinthe"res"

Addyourbackgroundintheverticalinthedrawable-portfolderandthehorizontalinthedrawable-landfolder.

OBS=>WITHTHESAMENAME!!!

3rd=>Bothyourhorizontalandverticalbackgroundshouldhavethesamename,sointhe.xmloftheactivityyoudothefollowing:

android:background="@drawable/background"

With this when the device is upright, the image contained in the drawable-port will be displayed and when it is moved horizontally the image contained in the drawable-land will appear.

About making 2 backgrounds, one vertical and one horizontal, take the following as an example:

horizontal ( 1280x720 ):

vertical(720x1280):

    
23.03.2017 / 21:49
-1

Just do a media queries for it. Type:

// Horizontal orientation

@media all and (orientation: portrait) { 

background-image: URL (image-horizontal.PNG) }

// Vertical orientation

@media all and (orientation: landscape) {background-image: URL (image-vertical.PNG)}

By the way I understood it:)

    
03.01.2016 / 00:09