Android save View position on orientation changed [duplicate] - android

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Android - disable landscape mode?
I can't save position of view when orientation changes.
I think it's because with orientation it also changes and I want that view stayed on the same position. For example of it was in the upper left corner of screen it stayed there and it doesn't matter what orientation of the device.
I'm using some kind of Absolute layout. Because I need to manage few screens at the same time.
So, i have x/y coordinate system. I think it's the main problem, but I can't solve it :(
I've attached images that you could see my problem.
As you can see first screen is portrait mode and View is located in upper-left corner, but when I changed to landscape mode position of view is also changed to upper-right corner.
And I need that position of view stayed always in left-upper corner.
http://imgur.com/qo19E&u2K0hl
http://imgur.com/qo19El&u2K0h
Sorry to bad screen. I'm still developing of an application and can't provide better screens :)
Ps: If you need some code, just say what part of code do you need.

Duplicate of Android - disable landscape mode?
You can force the activity to run in a particular orientation.
Inside the AndroidManifest.xml use the attribute "android:screenOrientation"
See here for an example:
http://developer.android.com/guide/topics/manifest/activity-element.html

It would be nice if you could provide some code or screenshots.
Anyway, when the orientation changes, your activity is destroyed and recreated.
If you have a well designed xml layout file (using linearlayout, relativelayout and properties like "wrap_content", "fill_parent"...) it will reload it in the onCreate() method, so all the resizing should be done automatically.
If your views can be moved by the user or are loaded from runtime values, you can save it. Look at this post for exemple : Override Orientation Change But NOT Restart The Activity AND Pass State Data

Related

All inflated items are vanished when screen orientation changes [duplicate]

This question already has an answer here:
Inflated items are gone when device orientation changes
(1 answer)
Closed 5 months ago.
Please somebody help me..
In my activity i use a loop to inflate items using LayoutInflator Service. There are some TextViews also in my activity. The TextView values remain unchanged but all the inflated items are vanished when i change the screen Orientation..
I know that the activity is recreated again to redraw the UI to match the layouts and all so I tried saving instance to a bundle. But helpless. Can i save these Inflated Items to that bundle and restore it on restore.
One guy told me to hide the soft keyboard when you change the orientation. I set properties on the manifest and also hiding keyboard on the orientation change event listener.
The only way now i can protect my app is to turn off the auto orientation. But thats not what i want.
In the manifest, put android:configChanges = "orientation" for this activity. This will prevent the activity from being destroyed and recreated when you rotate the screen.
Note that you have to be very careful when doing this. If any of your resources depend on the orientation configuration (like if you have a resource folder called values-land or drawable-port, etc.) then these resources must be reloaded after the configuration change. See documentation here.

Black Screen is showing for a while when screen orientation is changing

I am using one listview and one dynamic listview in the same xml but the problem I am facing is while changing the orientation in nexus 7 the screen is going black screen for a while and adjusting all the view in this time and In manifest file I specified screensize,orientation,keyboard-hidden for config attribute at activity attribute.I am handling required orientation changes in onConfigurationChanged() but still the black screen is showing for a while.Can you suggest me where I need to make the changes to work in properly
As the code length of code extends no of lines I am sharing my code with below link
Thanks in adavanc
https://docs.google.com/document/d/1dCIxgqX0vZIEbWfxWpLNkEDpu_-vd7HDfcGlYSInbHc/
You can't do a lot things in onCreate() and onResume(). any file operation and network operation should go to asynctask. the only thing you should do is manipulate UI. see http://developer.android.com/training/articles/perf-anr.html

Getting data from remote server and screen orientation issue in tablet

What I expected in my application is data coming from the server and everything, even the view, are dynamically created. The activity layout is divided into two parts. On the left is a list and on the right side are dynamic fragment changes. Whenever the orientation changes the server call is made again (As the activity is destroyed and re-created). This is working fine.
There are 3 fragments(2 are Maps) that have to be called from inside of each other on the right side of the layout.
Now I dont want this thing to happen. I don't want everything to refresh again and start from scratch.
I can't set configChange in the manifest, as the image sizes in the layout for landscape and portrait are somewhat different.
What is needed is a layout change on orientation change without re-creating the activity.
I have tried using onSaveInstanceState() and onRetainNonConfigurationInstance() but couldn't get it to work.
I think your solution is to set the configChange on your manifest AND create different layouts for portrait and landscape so you can have the results you are expecting: No refresh of the activity, and control the sizes of your ImageViews.

Android Application Layout

Hi does anyone know how to implement a layout change in the application. For example, when a user sees a text box prompt and turns the phone sideways and views the application as a landscape view. I have no idea how to go forward with this?
May I add that I know I have to create a layout-land xml. I'm ok with that bit, it's just I'm not sure how to make the phone automatically detect that it is oriented sideways and needs to implement the landscape view.
Many thanks.
If the phone supports orientation changes and you've turned it on in Settings (Display > Auto-rotate screen) everything should work automatically. The Activity will be restarted and the correct layout file used.
See this post here för details: Android: alternate layout xml for landscape mode

How do you create an app that only allows horizontal orientation?

I'm currently creating a side-scroller style game for my final year project for my degree.
I'm just wondering how you make the menu designed for when the phone is in horizontal orientation display, even when the phone is held in it's vertical orientation?
i.e. I want the user to know that the game has to be played with the phone in it's horizontal orientation and want the menu's to only display in the horizontal orientation.
Many thanks in advance.
Add the following attribute to your activity in your AndroidManifest.xml:
android:screenOrientation="landscape"
Well, I didn't get your question right,
but if you are defining your menu via xml
create a new folder in your res folder named
for layout changes:
layout_land
for horizontal specific menu:
xml-land
for horizontal specific drawables:
drawable-land
and define your menu,layout and drawable changes there.
Further you can tell android framework that you want to handle rotation changes:
by adding to your manifest(AndroidManifest.xml) activity child
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="landscape"
Comment exactly what you want.
Cheers!
Just complementing on other's answers
There are some different types of landscape and I think the best one is:
android:screenOrientation="userLandscape"
because it lets the user switch to landscape or reverse landscape using the device's sensor, or the user can block the swithing if he decides to.
I found that removing some basic controls of the user is quite annoying and should only be used if really necessary.
If you want to checkout other possible orientations just go here

Categories

Resources