I want to make independent layout from screen orientation.
Something like this:
(source: userapi.com)
Okay so what you want has nothing to do with the landscape mode, you just want the button text such that it seems that those are in landscape mode. I can suggest something which is kind of a hack.
For that you can have the buttons as usual with more height and less width and align them with left and the right edge of the screen.
For button text you need to make a .jpg or a .png of your text, rotate it and set that as the background for the button.(if you change button text dynamically then you need other snaps of text). This wont look good but it is one of the ways to do what you looking for.
You mean, you want to have seperate layout files for portrait and landscape views ?
Then you should create two different files each in layout and layout-land directory under res.
res
|_ layout
|_ layout-land
Android will call the appropriate layout based on the device configuration.
To retain the data, you may use
#Override
public Object onRetainNonConfigurationInstance() {
Bundle bundle = new Bundle();
return bundle;
}
and get the bundle in onCreate()
final Bundle savedBundle = (Bundle)getLastNonConfigurationInstance();
Related
I´ve made an app where´s just some text and a background image.
When I tilt my phone my background image gets streched out..
What I want to do is when I tilt the phone I get now background image.
What you need to do is create different layouts for your views in landscape and portrait mode and put the landscape ones in res/layout-land and the portrait ones in res/layout-port. Simply get your current XML file and copy it into both the portrait and landscape stalks and then just change the drawable that is referenced for the background. That way you can have one that fits well for portrait and another that you've edited to fit for landscape views.
you need to provide a different layout for that orientation.
create a layout-landscape folder, and in that layout change the background to the one you want for your landscape layout. besides you can completely customize your landscape orientation that way.
yes you can change the background
for that you have to create another xml file with same name of the xml you are using right now
then copy all the code from your previous xml to this new xml
you have to create this xml inside the land named folder,if that folder dosent exist than crete a folder name land inside your layout folder..
you just have to change one thing in your xml and here you gooo
android:background="#drawable/yournewbackgroundname"
do not change any thing in our old xml
Is it possible to have two Views in Android; one of which is the "background" and wont rotate when the device is rotated. And have the other one on top (the "UI-elements") rotate on orientation change?
I know I can disable/enable orientation changes for a whole activity but how would I go about that for separate Views in one activity?
I'm not sure if that's possible, but usually to support "landscape" and "portrait" orientations, you would create another folder in your "res" folder and call it "layout-land" then copy your .xml file in "layout" to "layout-land" and make the appropriate changes to your UI-elements.
If you want to keep the background the same, then I suppose you can leave it unchanged or you might have to rotate the image and save a copy of the rotated image to use in landscape orientation.
Hope that's helpful!
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?
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);
}
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.
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..
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...
If I got a graphic design for lets say a TextEdit control as a background image, is it possible to stretch the image when changing from portrait to landscape view?
I'm coming from WEB and with CSS where I could divide the background picture to 3 parts and make the background stretch dynamically. Is something like this possible in android environment or should I use different layouts for each orientation?
You can declare different graphics by dropping them in separate sub-folders of the /res directory in your project. By naming convention, your application will pick them up automatically.
For example, if you use a background image called textBackground.png and you have two versions of it depending on orientation. The app will use res/drawable/textbackground.png by default and res/drawable-land/textBackground.png when in landscape mode, for example.
Check out this doc for the full story:
http://developer.android.com/guide/topics/resources/providing-resources.html
I want to change some views when the orientation changes for example i want to put text view from bottom of the screen to screen's right side vertically when the orientation changes from portrait to landscape mode.How to achieve it?
Create two distinct layouts with the same name (i.e. mylayout.xml), and put one in res/layout-port and the other in res/layout-land. If you call
setContentView( R.layout.mylayout );
in the onCreate() method of your activity, then Android will select the correct layout depending on whether the device is in portrait or landscape orientation.